Hello.
I've searched the forum but have been unable to find how to open a form to a specific record using a script. I have the id, I just want to do something like FormName.Show(id of the record I want to see on screen). Any help appreciated. Thanks.

2

(1 replies, posted in Script)

Arghhhhh.
<embarrassed>
          I was referencing the wrong TableGrid control in the dbUpdate method.
</embarrassed>

I have a PageControl on a Form. The form's name is Master.
On Page1 of the PageControl I have a TableGrid1. When I double-click a row in TableGrid1, it opens Form1. Form1 gets its data from DatabaseTable1
On Page2 of the PageControl I have a TableGrid2. When I double-click a row in TableGrid2, it opens Form2. Form2 gets its data from DatabaseTable2
On Form2 I have a button. The button executes a script to copy records from DatabaseTable2 to DatabaseTable1. This works. Records are copied. I've confirmed using DB Browser for SQLite.
The last step in the script executes Master.TableGrid1.dbUpdate so that the records I've copied from DatabaseTable2 to DatabaseTable1 will show up in TableGrid1.
I thought that the dbUpdate method would requery TableGrid1's record-source and displays the new records. This doesn't seem to be happening.
However, when I close Master and open it up again, I see the records in TableGrid1.
Hopefully, I've made myself clear. Any help appreciated. Thanks.

@Dmitry & @Jean - I'm running Windows 10 too. Did a search and came up with the following that works for me.
Uncheck the box "Always ask...when opening this file..." when you first open the file. Afterwards, the popup no longer appears and you can read the CHM file's contents. After doing this the file opens as expected - no need to rely on 3rd party software, but thanks, @Jean for posting what worked for you smile.

@Dmitry - Thanks for the Bergsoft info, but the help file is empty - just a TreeView on the left with no content displayed when clicking on one of the TreeView nodes sad

6

(8 replies, posted in Script)

@Dmitry - Many thanks. Downloaded. smile

@Dmitry - That was exactly what I was looking for - thank you! I have one question though, is TdbStringGridEx referenced anywhere in the documentation or the functions reference in the code editor? I couldn't find it. Anyway, I've added an example project file to show how I'm using it. Hope it can help some other forum members.

@jean - Many thanks for your response. I mistakenly included the wrong procedure in my previous post. My apologies. I have created the code below and it works fine for colouring alternate TableGrid rows. My question is how do I pass a TableGrid object (and the Form object) into the procedure so I can use the one procedure to colour alternate TableGrid rows no matter what form they live on in my project? If I had 20 forms in my project, each with a TableGrid on them, would I have to duplicate this procedure 20 times? Ideally, so I didn't have to duplicate code for each Form/Tablegrid object, I would want to call just one procedure and pass into it the form (on which the TableGrid object lives) and the TableGrid object who's rows I want to colour. The procedure's signature would perhaps look like this:

AlternateRowColours(<The Form object that holds the TableGrid object>,<The TableGrid object whose rows I want to colour>)

I hope this makes sense. Any help greatly appreciated. I'm having a blast with MVD.

 procedure AlternateRowColours;
var
   i,k,r,c: integer;
begin
     r := frmExpenseDS.TableGrid1.RowCount - 1;
     c := frmExpenseDS.TableGrid1.Columns.Count - 1;
     for i := 0 to r do
          begin
           if i mod 2 = 0 then
              begin
                for k := 0 to c do
                  begin
                    frmExpenseDS.TableGrid1.Cell[k,i].Color := $00F0F0F0;
                  end;
              end;
          end;
end;

9

(8 replies, posted in Script)

@Dmitry - Many thanks for the link to 2.8 and the example code. Unfortunately, the XML is the response from an HTTP GET request - not a file I can load using LoadFromFile(<filename>). I could use the PosEx though. Which leads me to a question. When does 2.8 come out of Beta. I'm wondering about using the beta just to obtain the PosEx function smile.


@bemorhona-qt - Also many thanks for your code example.

Hello.
I've created two procedures. ShowAlternateRowColours and ClearAlternateRowColours. They turn on/turn off alternating row colours in a TableGrid. As I want to use these procedures for all TableGrids I create, how can I call these procedures and pass them a tablegrid object? Ideally, it would look something like the code stub below. I'm fairly certain I'll need to instantiate a TableGrid object and pass that into the procedure, but I don't know how to do that. Many thanks.

procedure ShowAlternateRowColours(<TableGrid>);
var
   i,k: integer;
begin
     for i := 0 to frmExpenseDS.<TableGrid>.RowCount - 1 do
         begin
            for k := 0 to frmExpenseDS.<TableGrid>.Columns.Count - 1 do
              begin
                frmExpenseDS.<TableGrid>.Cell[k,i].Color := $00F0F0F0;
              end;
         end;
end;

11

(3 replies, posted in Script)

Thank you, Dmitry. That makes loads of sense - and provides me a way to help organize the code.

12

(3 replies, posted in Script)

Hello.

It looks as though MVD has a single code page called script that is used to store all code regardless of which form/control it's attached to. How are you organizing this one-page script when you have lots of forms with lots of code for each of the forms? Is it as simple as creating commented "headers" identifying the form and putting all code under the header? I'd appreciate hearing what you do to keep your script file straight.

Many Thanks.

13

(8 replies, posted in Script)

Thanks for the suggestion, Dmitry.

However, I don't think my version of MVD (2.7) has the PosEx function.

It's not as robust as I'd like, but I was able to implement it this way. sResponse contains the contents of the XML file.

begin
    int1 := Pos('<text>',sResponse);
    int2 := Pos('</text>',sResponse);
    sTime := Copy(sResponse,int1+6,int2-(int1+6));
    sResponseCopy := Copy(sResponse,int2+6,Length(sResponse)-(int2+6));
    int3 := Pos('<text>',sResponseCopy);
    int4 := Pos('</text>',sResponseCopy);
    sDistance := Copy(sResponseCopy,int3+6,int4-(int3+6));
    MessageDlg('The distance between ' + Splash.Edit1.Text + ' and ' + Splash.Edit2.Text + ' is ' + sDistance +'.'+#10#10+'It will take ' + sTime + ' to get there.',mtInformation,mbOK,2);
end;

14

(8 replies, posted in Script)

Hello.

I have an XML file comprising:

<?xmlversion="1.0"encoding="UTF-8"?>
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>London,UK</origin_address>
<destination_address>Hastings,UK</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>7471</value>
<text>2hours5mins</text>
</duration>
<distance>
<value>122507</value>
<text>123km</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>

It's actually one long line of XML. It seems as though this forum editor has inserted the CRLFs.

I'm drawing a blank on how to extract the time (2hours5minutes) and distance (123km) elements. Does MVD have an XML parser?
Thanks

15

(3 replies, posted in General)

@ehwagner - Many thanks for your example application. A hidden text field that gets its value from the combobox and is bound to a field in the table is a great idea.

@Dmitry - I'm still struggling a bit with your suggestion, but will keep at it.

16

(3 replies, posted in General)

Hello.
I'm currently evaluating MVD and so far, I'm very impressed.
I do have some pre-purchase questions though. Hopefully, Dmitry or some other knowledgeable forum member can help.
I know that FormName.ComboBox1.Items.Add('value_I_want_to_add') allows me to add values to a ComboBox without using a dictionary table.
How do I map the "hard-coded" values in the ComboBox to a field in my table? I'd like to let MVD do the "heavy-lifting" of binding the fields on my form to the Database table using the TableName/FieldName properties, but for a ComboBox, all I see is ForeignKey/FieldName - so it's obviously expecting me to use a dictionary table. Any help appreciated.
Many thanks.