326

(0 replies, posted in Script)

I am getting a messagebox error - Could not convert variant of type (Array Variant) into type (integer).


My code is:


MessageDlg('Are you sure you wish to DELETE Technician ' +frmMain.cmTechSelect.text, mtConfirmation,
 [mbYes,mbNo], 0);

I thought as it returns an integer, I'd try the above with Result:=. Same error message.


Then I tried just one button type, no joy, so I removed the reference to the combobox and still I get the error.


This is syntax that I have used in Delphi and it works.

{The Answer}

I suddenly realised that unlike Delphi or FPC , MVD sees [] as an array.


I changed the above to MessageDlg('Are you sure you wish to DELETE Technician '+frmMain.cmTechSelect.text, mtConfirmation,mbNo+mbYes,0);, and now everything works!

Thanks for the reply EHWagner,


I did try that initially, but it never correlated  the item list ID in the combobox with the ID in the database.


Example:


Combobox  list item ID.


itemIndex_1.  supplier A
itemIndex_2.  supplier B
itemIndex_3.  supplier C
itemIndex_4.  supplier D


Database item ID by row.


dbID_1.  supplier A
dbID_2.  supplier D
dbID_3.  supplier C
dbID_4.  supplier B 

This is taken from the actual contents of my database and the item list in the combobox which is sorted by ascending name.

obengappiah1 wrote:

Please my save record cannot be saved and display in the table grid view...please any help

Can you upload your project?

Or describe more what you are trying to do and what error you are getting.

329

(6 replies, posted in Russian)

Sample of checkbox in action

330

(6 replies, posted in Russian)

Have you tried selecting the checkbox option under the gridtable settings? You can then select which column you want it to appear in.

I've attached two images that might help.

After posting this cry for help, I carried on trying various things and solved it with this.

procedure frmMain_btnEditSupplier_OnClick (Sender: TObject; var Cancel: boolean);
var
    RecordID:string;
    RecordNo:integer;
    supName,recordString,test: string;
begin
// check item ID for debugging
    RecordNo := frmMain.combobox2.ItemIndex;   // database ID number for text selected 
    supName := frmMain.combobox2.Text;  // Text of item selected in combobox
  
  //SQL test
    recordNo := SQLExecute('SELECT id FROM supplier WHERE sup_name= "'+ frmMain.ComboBox2.text + '"');
    test:= SQLExecute('SELECT sup_name, id FROM supplier WHERE sup_name= "'+ frmMain.ComboBox2.text + '"');

//start DEBUG message
    showMessage('Test= ' + test + ' Record No: ' + intToStr(RecordNo) + ', recordstring ' + recordString + ', supplier ' + supName);
 //end of DEBUG message

   ShowRecord(frmEdit,'supplier',RecordNo); // show form EDIT using table supplier and database recorrd ID
end;

I'm wanting to select an item in a combobox, then click on an 'edit' button which will open up a second form with the edit box filled in with the text of the item selected in the combobox. Subsequently that item will be edited and then saved back to the database.

I've tried the code below, but that is using the 'item ID' in the database which is not in the same order as the combobox.

It works, but displays the wrong item in the edit box, which of course means the wrong item gets edited and updated back in the database.

Should I change this to a SQL statement ?

procedure frmMain_btnEditSupplier_OnClick (Sender: TObject; var Cancel: boolean);
var
    RecordID:integer;
begin

    RecordID := frmMain.combobox2.ItemIndex; //get item number from combobox list

// check item ID for debugging
    showMessage('item no ' + intToStr(RecordID));

   //ShowRecord(frmEdit.,'supplier',frmMain.ComboBox2.ItemIndex );
   ShowRecord(frmEdit,'supplier',RecordID ); // Open edtForm with item selected ready to be edited and saved back into database.
end;

333

(17 replies, posted in General)

leprince2007 wrote:

The app doesnot work,it shoes error in line 31


leprince2007,  do you mean when you try to run the program you get an error?

I've just run the program with no error.  Try downloading the zip file again and run.

What build of MVD are you using? ehwagner is probably using v6.2 or possibly beta 6.3.

Just trying to work out why you get an error showing.

334

(3 replies, posted in Script)

Thanks for the pointer, the syntax change has solved the error.

335

(3 replies, posted in Script)

I'm having a problem getting my SQLExecute statement correct.


I wish to delete from the database an entry I select via a combobox, Like wise I am also looking at editing an entry via combobox selection.


I have tried  SQLExecute('DELETE FROM supplier WHERE sup_name='+ frmMain.ComboBox2.Text);  which produces the syntax error shown in the attached image. I first of all though I should be using dbItemID SQLExecute('DELETE FROM supplier WHERE sup_name='+ frmMain.ComboBox2.dbItemID);, but that just gives me an ID of -1.


The following SQL works in DB Browser for SQLITE FROM supplier WHERE sup_name="Corsair"+"Trading".


Neither actually deletes the  file in the database. Once I understand what I'm doing wrong here, I think my 'update' for editing an entry should follow the same syntax structure.

I'm too far down the track, to change my comboboxes to tablegrids, whcih of course would allow me to use the inbuilt DELETE and UPDATE records.

336

(17 replies, posted in General)

I think I now understand what you are looking for.


1. A daily checklist of items. Some are performed weekly and others monthly. Checkboxes are used to tick off the tasks that have been completed that day/week/month.


2. Each day's checklist results are saved to the database. Saved to database as ROW_x Date, checkbox1, checkbox2, checkbox....... (1= done, 0 = not done) next day ROW_x +1 has the new row of the above data layout.


3. By selecting previous dates from the date time picker you can bring up previous checklist results. As you select previous dates, the data for the ROW corresponding to the date selected is read from the database and the boolean results for each checkbox column (in the database) are shown against each checkbox with a label changing colour, depending on the date taken from the Date column in the database..


4. The label changes colour depending on the difference between (today's date - date selected in the date column/row of the database). IF the difference between today and date selected is 1 THEN the label or font :=  coloured green,  ELSE IF the difference is >1 the label or font := coloured red.


If this checklist was a piece of paper on a clipboard, each day would have a new sheet of paper placed on top of yesterdays sheet of paper on the clipboard.  Each sheet of paper has the date it was actioned. By sheaving through the paper forms on the clipboard you would be able to see by date what had or had not been checked.


Is that what you are hoping to achieve?

337

(17 replies, posted in General)

leprince2007,

Are you aiming for a Daily 'Todo' or 'Checklist'  and you then save completion or not to the database?

You can make DTToday visible again by just ticking the property box.

Could you explain what you want to happen if you select an earlier date than 'today' from your date time picker?

I thought ehwagner had got pretty close to what you needed.

To convert your visual basic script you want something like this:

1. to make it easier you should have a hidden tablegrid, then you can address cells directly

var
    row, column: integer;
    rowcnt, colcnt: integer;

 for row := 0 to rowcnt do
       for column := 0 to colcnt do
       begin

          if form1.tablegrid1.cells[column, row] > 1 then
             label1.caption := form1.tablegrid1.cell[column, row].AsDateTime
        end;
end;

I haven't tried this out, but it is close to your VB script.

If you want the label to change colour then add in

form1.label1.font.color := clGreen;

Just to make sure what you mean.

Are you wanting to use a button on your keyboard to activate a button_on_click action?

Or, are you wanting to know how to code the on_click event for a button on your form?

339

(1 replies, posted in Script)

Hi Jeffmtl,


You've become confused with the end of line semicolons.

Try the following:

procedure fmClientInfo_Button17_OnClick (Sender: TObject; var Cancel: boolean);  // shortcut button with a path on hard drive
var
       strLink : string;

begin
        strLink := fmMyform.cfDriveLink.text;

        if strLink = '' then   //[color=BLUE]Unlike C, you do not need parentheses for simple statements[/color] 
           
                ShowMessage('No link') // [color=blue]Begin/End is not needed for a single statement, NO [b]; [/b]needed if only one statement after the IF clause[/color].
          
        else
           
                OpenURL(fmMyform.cfDriveLink.text);  //[color=blue] [b];[/b] is needed at this statement[/color]
           
end;

For a reference, you could look up Freepascal.org or Lazarus

Thank you sibprogsistem and Derek,

I completely overlooked the 'Close form ' option in the action dialogue. I must have ticked that when I was going to have an extra form pop up and then send an email with the order details.

Most grateful for your assistance.

Thank you Derek,

As always such a simple solution.

At least it helps me understand how MVD works internally for future reference.

As the topic subject says, when I click a button whose action is to Save Record, it saves the record  and then closes the program down.  I don't have any events attached to this button, and can't for the life of me work out why it is doing this.

I've attached the program if anyone is able to help.  The problem button is the 'add order' button on the Create Order tab.

I'm a little stuck, I have a database which has some calculated fields for dates.

I have written a SQL query and want to reference the calculated field that I have created in MVD.

My calculated fields cfDateRec and cfDateReq (which work when I let MVD do all the work) is:

strftime('%d ', rec_date)||(substr("--JanFebMarAprMayJunJulAugSepOctNovDec",strftime('%m', rec_date)*3,3)|| strftime(' %Y', rec_date))

.

The SQL I have so far in the search function is.

SELECT
a.tech,
b.sup_name,
c.part, 
c.requestdate,
c.rec_date

FROM
techname a, supplier b, requests c 

WHERE 
c.id_techname = a.id  AND
c.id_supplier = b.id  AND 
((a.tech LIKE '%{edtSearch}%') OR
(b.sup_name LIKE '%{edtSearch}%') OR
(c.part LIKE '%{edtSearch}%')); 

I am hoping to parse c.requestdate and c.rec_date through the above Pascal calculated field.

I have tried letting MVD to do all the work using the 'Search' action from a button, but this fails as it keeps inserting a '.' in the WHERE clause which makes the whole thing fail.

I can post the project if that helps.

344

(3 replies, posted in General)

I don't know if this is possible in MVD, but in Delphi you can have a separate unit that contains a record of all the buttons and labels for a form:

unit formstuff;

interface

TFormMainLabelsText = record
   Title,
   ButtonText,
   SomeText: string;
end;

implementation

Then in a View script/unit declare a class that has private calls to you the record, this allows you to alter and display on different forms just using one set of components.

unit viewform

interface

uses formstuff;

type
TMainFormLabels = class
private
   fMainFormLabels: TFormMainLabelsText;
public
  function GetLabelsText:TFormMainLabelsText;
  constructor Create;
  destructor Destroy; override;
end;

implementation

function TMainFormLabels.GetLabelsText: TFormMainLabelsText;
begin
  fMainFormLabels.Title:='Some Title';
  fMainFormLabels.ButtonText:=' This is a button';
  fMainFormsLabels.SomeText:= 'Some text';
  result:= fMainFormLabels;

In the main script/unit  you then reference the viewform and here you can then link the buttons and labels on a form to the ones n the formsstuff unit.

You create as many records as the text button types you need.

I've only used this sort of method once, as personally I find it very 'circular', but pure object programmers seem to love this kind of stuff, whereas I think procedural code is easier to follow and maintain. But, I'm not modern anymore sad

I'm sure there is an easier way to do this, but wanting to be different, I prefer to show my dates in a tablegrid as '01 Jan 2020' instead of 01/01/2020.

After spending a large part of my day trying to figure it out, I have succeeded with the code below. Note this uses a Calculated field to convert the date from SQL format to my preferred display format.

strftime('%d ', rec_date)||(substr("--JanFebMarAprMayJunJulAugSepOctNovDec",strftime('%m', rec_date)*3,3)|| strftime(' %Y', rec_date))

Replace 'rec_date' with the column name in your database that contains your date.

Hope someone might find it useful.

346

(4 replies, posted in General)

Here is a link to a topic which I think you could use to solve your question.

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

347

(4 replies, posted in General)

Humblelion, 

I think for your purposes a lookup field is what you need, I'm not the best with databases as yet, so I could be wrong.

After you have calculated the daily sales, do you need to write that to the database or just calculate it everytime you access the database?

Thanks Derek,

I don't know why I keep making things so difficult for myself!

I'm trying to make a table grid cell not editable once it has a value in it.

The below code works for checking if a cell is empty and allows in this case a date to be entered. It also allows the date to be changed again just by clicking on column 5, which what I don't want to happen. Note this is not using the datetimepicker  as a visible component.

if Acol = col then //check if column 5 has been clicked
    begin
     //If column 5 has no tick in the checkbox 
        if frmMain.grdOrders.Cell[col,ARow].Empty = false then
        begin

        // update the grid with the date in column 4
            frmMain.grdOrders.Cell[(col-1),ARow].asDateTime := dt;  {dbdate function does not work here}
      
 // update database
            sqlexecute('UPDATE requests SET rec_date = "' + DBDateStr(dt,1)+'" WHERE id =' +
           (frmMain.grdOrders.sqlValue));
        end;
   end;

However if I write this, the complete grid table no longer allows the date to be entered on the empty date column 4.

if (Acol = col) AND (frmMain.grdOrders.Cell[4,Arow].AsString = Null) then 
  
    begin
        if frmMain.grdOrders.Cell[col,ARow].Empty = false then
        begin
            frmMain.grdOrders.Cell[(col-1),ARow].asDateTime := dt; 
            sqlexecute('UPDATE requests SET rec_date = "' + DBDateStr(dt,1)+'" WHERE id =' +
           (frmMain.grdOrders.sqlValue));
        end;
   end;
 end;

I've tried using frmMain.grdOrders.Cell[4,Arow].AsString = '', I've tried removing this part of the code from AND and using an If statement instead and I've tried changing  frmMain.grdOrders.Cell[4,Arow].Empty = True.
None seem to do what I'm hoping for.

Thanks Derek, that solved my problem.

The reason why I'm going for a checkbox to enter a date is because:

1. I want a user to definitely select a 'date received' rather than perhaps accidently clicking on the grid and entering a date, as this is a one time entry. No reversal allowed, or mistakes for that matter smile

2. I intend to have a double click on a specific cell, similar to your example and open up another form.