Topic: New to MVD

Dear all. i'm new to MVD and i started working on my database

I Was hoping to get two scrips working:

This:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    if Form1.Edit1.Text = '' then
    begin
        Cancel := True;
        ShowMessage('Your message here.');
    end;
end;

And then i want to use another script (that i can't find it now) that allows me to check if a combo box has an id (example id = 2) it would require a certain box (or in this case another combobox) to be selected...

The problem is, every time i paste a script to my "script" area, the script shows me an error: Begin expected at (12:1 in this case)
Even if i debug the script and rewrite it until it works, it does nothing


P.S. the script i pasted is the "generic script" that i copied from this forum, of course that i'm smart enough to change the camps like: procedure form1_button1_onclick to: "myformname"_"theokbuttonname"_onclick etc etc... smile

Thanks in advance

Re: New to MVD

Hello VascoMorais,


I am not sure about your conditions, so this is just wild guess.


If both conditions can be tested at the same time, you could try something like :


if (Form1.Edit1.Text = '') AND (Form1.Combobox1.dbItemId = 2) then
    begin

    end;

Note on this code :

  • multiple conditions must be between ( and )

  • you can use OR operator to test if one or both conditions are true

  • After Christmas, I'm a bit confused, you might want to try ItemIndex instead of dbItemID...


Or you could nest your conditions to get a second action with just one click :

if Form1.Edit1.Text = '' then
    begin
        Cancel := True;
        ShowMessage('Message 1');
            if Form1.ComboBox1.dbItemId = 2 then
                begin
                    ShowMessage('Message2');
                end;
    end;

I have never called a procedure form inside another procedure, but I know tthis is possible. Check this thread on the subject :

http://myvisualdatabase.com/forum/viewtopic.php?id=1885


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: New to MVD

Well, final i was able to write something on the script, thanks to you.
But i am looking for the right call for a button, using if & and's is working for me, but i am looking for the right call for a button being pressed, i am trying to write this:

Begin

if (frmAssistencia.BTGRAVAR.OnClick) and (frmAssistencia.memoavaria.Text = '') then
    begin
        Cancel := True;
        ShowMessage('Your message here.');
    end;

end
.

Of course it doesn't work because i don't know how to write this procedure.

Is there a dicionary avaiable for these procedures?
Is this SQL language?
I am completly new to SQL smile

Re: New to MVD

VascoMorais
Not sure what exactly you trying to do, you can attach your project (zip file without exe and dll) with description and I'll try to help you.


You can press button from script in the following way:

Form1.Button1.Click;



Script is pascal language (not SQL), so you can use any book about Pascal language.

Dmitry.

Re: New to MVD

Hello again smile

Let's begin with the simplest things : No this is not SQL language, this is Delphi (Object Pascal). You'll see, both are pretty easy and even funny. Delphi is for programming  conditions and actions that MVD does not do natively. SQL is for getting info from a database (SQLite or MySQL with MVD).


There are tons of good info sources on the forum and on the web. Do not hesitate if you have questions on any, people here are fast on answers smile


Now , regarding the script you are trying to write : I am not sure you can test if a button is pressed outside the onclick procedure of this button. We will wait for others or Dmitry's answer, but this would mean you have some kind of background process waiting for that particular button to be pressed. I don't know how to do that, or even if it is possible.


What you could do is

procedure frmAssistencia_BTGRAVAR_OnClick (Sender: string; var Cancel: boolean);
begin
       if frmAssistencia.memoavaria.Text = '' then
              begin
                        Cancel := True;
                        ShowMessage('Your message here.');
               end;
end;

To me, this is the same, except that the BTGRAVAR click test is true because it has been clicked. That leaves you just to test the memoavaria content to test


Let's wait for the others reaction


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

6 (edited by VascoMorais 2015-12-28 22:23:58)

Re: New to MVD

Hello there Dimitry, thanks for replying me, i am still trying to figure out how to work with MVD, but i am hoping to get this working properly.

I don't know if the buttons are called Formname_ButtonName_Onclick or  Formname.ButtonName.Onclick so i tried both, none work, the button doesn't cancel it's action when i press it to save the form, warning me that i have to fill a specific edit box.

If you can point me in the right direction i'll be glad smile
Many thanks

Re: New to MVD

i think i know what my problem is... lack of programming skills, i just found out (my myself) that a end with ; means that there's more code below, and an end with . means that's the end of the code...

Re: New to MVD

here's the database , i forgot to attach the other files

Re: New to MVD

I dont know why i can't attach files, but here's what's going on:

i've got litteraly this writte on the script:


   procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    if (Form1.Edit1.Text = '') then
    begin
        Cancel := True;
        ShowMessage('Your message here.');
    end;
end;
begin

end.


The form name is exacly named: Form1
The text box is named Edit1
and the button that saves the form into the table that i named "testes" is named... Button1

I Run the script, it doesn't show any errors, i press button1 without inserting anything on text box, it just saves an empty name.
can't make this thing work... maybe it's a bug?

Re: New to MVD

Nevermind...
As you guys probably figured out, i'm new to programming, but i know what the problem was
I didn't specified the procedure to the button...
Just added frmAssistencia_BTGRAVAR_OnClick to the "onclick" field on the button and the script now works perfectly.

Many thanks dimitry and mathmathou

Re: New to MVD

Hello Vascomorais

If you are new with MVD (we were all even those who finally got by mastering it),
there are two documents that you may find useful :

Here you can find documentation (in english) of My Visual Database:

General documentation about MVD
http://myvisualdatabase.com/help_en/

Tutorial about My Visual Database
http://myvisualdatabase.com/download/MY … MANUAL.pdf

You have also videos created by Dmitry that can be of great help with step by step

JB

12 (edited by VascoMorais 2015-12-30 03:04:43)

Re: New to MVD

Hi, thanks, i have been reading a lot about pascal, i managed to create lots of stuff...
I can't however, send emails, i think gmail is closing my connections instantly, and i have already turned on the "less secure apps" option on my gmail.

i am using this script dimitry send:

procedure Form1_bReport_OnAfterClick (Sender: string);
var
    sFile: string;
begin
    Form1.bReport.Enabled := False;
    Form1.bReport.Caption := 'Please wait...';

    sFile := Form1.frxPDFExport1.FileName;

    if FileExists(sFile) then
        if SendMail('smtp.gmail.com, 'username@gmail.com', 'password', 465 , 'my name', 'destination email', 'Subject', 'Message', sFile) then
            ShowMessage('Message sent');

    Form1.bReport.Enabled := false;
    Form1.bReport.Caption := 'Send PDF to e-mail ';
end;

begin
    Form1.frxPDFExport1.OpenAfterExport := false;
end.

it gives me "connection ended gracefully (lol)

My intention is to have this code working, and then adding something like:

sEmail := Form1.edit1.text; on the "destination email" so it could send an email automatic to the email that is on this specific field

could you guys give me an hand? thanks


EDIT: it seems that it doesn't work with either Yahoo, Gmail or Outlook, but... i created an email @ portugalmail, it uses port 465 too but it doesn't use ssl that's the only difference, i was able to configure the script correctly...
Could this be that the command for sending the email (sendmail) doesn't have a field for ssl connections?

EDIT2: Need an extra help with something:

I am able to get a string from a textbox to send my email, here's the code i used:

procedure main_btemailfo_OnAfterClick (Sender: string);
var
    sFile: string;
    sEmail: string;



begin
    main.btemailfo.Enabled := False;
    main.btemailfo.Caption := 'Please wait...';

    sFile := main.frxPDFExport1.FileName;
    sEmail := frmassistencia.BxClienteEmail.sqlValue;
    if FileExists(sFile) then
        if SendMail('smtp.portugalmail.pt', 'xxxxxxxxxxxx@portugalmail.pt', 'xxxxxxxxxx', 465 , 'xxxxxxxxxxr@portugalmail.pt', 'xxxxxxxxxxxx@gmail.com' , 'subject', semail, sFile) then
            ShowMessage('Message sent');

    main.btemailfo.Enabled := true;
    main.btemailfo.Caption := 'Email ';
end;

Now... picture this:

I have two tables: one named table1, and another one named table2
I have linked the table1 table with the table2 table, and i have a table1_id value
I have the email value on the table1 , and i have a combo box on (lets imagine) form1
this combobox is the table2.table1_id , and i have choosen to pick them using their phone (names would be too long, emails some people don't have, etc... etc...)
in form1 i have a text box pointing to table1 "email" value , it doesn't get updated automatic when i choose the combo box related to the customer i want, but when i reopen form1 after i save it, it will show up there...

My question is: is there a way to automatic update the form1 ? i mean... i guess i have to save it contantly and retrive it (save & show) probably....

Otherwise:

Is there another way to pick the "email" data that's on the right customer associated to the right combobox value ?
I hope you understand my question smile
Many thanks

p.s. i know the "semail value" on my code is on the "message field" but i was trying to debug and see what's going on each time i switched it arround, so i would get an email showing that value i was getting each time i changed my selection,  i know i could use a simple "show message" text but i only remembered it later...