251

(2 replies, posted in General)

As MVD doesn't allow multi-dimensional arrays, is there a work - a - round other than declaring a number of individual strings and then concatenating them together?


Basically I'm building the body of an email text. I need to read in 4 columns of a database and then display them as one string, and repeat this for however many rows I need to read in.


My thinking was to read in 4 columns and assign them to one row and then use a TStringlist to add each complete row and then use the 'text' method  of the TStringlist to be the  'body' of the email.


So in  the database I have - column 1, column 2 column 3  on each row.

I need to 'format' this so that in the email  it looks like one 'sentence' and repeat this for however many rows have the information I need to send.


I thought about using a non visible Rich Text Box and then using that result as the body of an email, but that seems to be an unnecessary step.

I hadn't realised that date('now') is connected to a specific timezone.

Where I live it is currently 10:20am on 1/6/2020 - however up until 30 minutes ago using the SQL date function was reporting itself as  31/5/2020 - according to SQL the time is presently  18:20 1/6/2020.

Which goes to show that if you want accurate time and dates, the datepicker is the component to use.

It certainly caught me out, and only because I was testing a database and couldn't work out why at 7:30am on 1/6/20 SQL date was insisting it was still 31/5/20.

253

(2 replies, posted in SQL queries)

Thank you sibprogsistem,

As you suggested, I separated the two fields into two statements and that works fine.

254

(187 replies, posted in General)

I suggest a new property for Comboboxes.


The option for it to 'SELECT' by DISTINCT or not. Currently the SQL it uses for populating the combobox just uses SELECT, and for many purposes this is fine. But there are cases where it would be useful to populate the combobox using SELECT DISTINCT, and a property to enable or disable this option would be nice.

255

(2 replies, posted in SQL queries)

I have written a procedure that is used to receipt a complete order assuming there are no discrepancies. The amount of items on the order can vary from 1........ Many.


The plain SQL tested in SQL Studio is:

UPDATE orders SET receivedQty = '10', receivedDate = date('now') WHERE orders.orderRef = 'REQ 277/12' AND orders.id = 3;

Now I have converted it to the SQLExecute statement below, but it is not working, it never updates the database. Does MVD work with logical ANDs in the SQL statements? Or will I have to write the above SQL as two lines of code?


procedure receiveOrder_btnReceiveAll_PO_OnClick (Sender: TObject; var Cancel: boolean);
var
 indx, received : integer;
 s :  string;
 ds : TDataset;
begin


   indx := 0; {index counter for iterating through available rows of DB grid}

   { Get the Order ID from Orders table for all matching purchase orders, place result into the dataset}
   sqlQuery('SELECT orders.id FROM orders WHERE orders.orderRef = "' +receiveOrder.cmbPO.Text+'"', ds);

   ds.First; {Make sure we are at the beginning of the dataset}

   {All the work is done here.
    Assign the orders.id to 'S', copy qty ordered to qty received store in 'received' then update the records in ORDERS
    with 'received Qty' the Date received matching the order Id and PO number}
   while not ds.EOF do
   begin
       s := ds.FieldByName('ID').asString;
       received := strToInt(receiveOrder.tgReceiveOrder.Cells[3,indx]);
       sqlexecute('UPDATE orders SET receivedQty = '+ intToStr(received) +', receivedDate = date(''now'') WHERE (orders.orderRef = "'+ receiveOrder.cmbPO.Text +'") AND (+ orders.id = "'+ s +'")');
       showmessage('order Id ' + s); // temporary debug check to make sure order.id is correct
       ds.next; {move to the next record}
       indx := indx + 1; {increment counter for the tablegrid row.}
   end;

   ds.Close;  {Close the dataset and free the database}
   ds.Free;
   showMessage('Complete Purchase Order Receipted');

end;

256

(1 replies, posted in General)

I have solved the problem, I realised that to trap the 'control' keys you have to use either OnKeyUP or OnKeyDown!

257

(1 replies, posted in General)

I am using MVD v6.3 and I'm trying to capture the 'enter' key in an OnKeyPress event.

Neither VK_RETURN or #13 is recognised, which I find very strange. In fact for either of the previous only the backspace key is recognised.  Incidentally the VK_BACKSPACE constant is not in MVD but #8 is.

procedure receiveOrder_tgReceiveOrder_OnKeyPress (Sender: TObject; var Key: Char);
begin
   if (Key) = #13 then   // alternative code,  if ord(key) = VK_RETURN;
   begin
     Key := #0;
     showmessage('I am in the key trap ' + Key);
     receiveOrder.tgReceiveOrder.dbUpdate;
   end;
   showmessage('key ' + Key);

I have tried two different keyboards and both have all keys recognised apart from the enter key.  I'm using W10 and the language is UK English and US keyboard layout.

Anyone else find they can't trap the enter key?

I amended my post while you were replying - see AnsiChar for B, Buf and tmpLine

Should BUF and S be an AnsiChar instead of a char?

Don't forget a CHAR is only one single character. and only goes to 255 decimal, You have 848 being tested.

260

(1 replies, posted in Russian)

Does this help? (In Russian)

http://myvisualdatabase.com/forum/viewt … 151#p36151

sdHale,

I haven't tried the above code, but it might depend on where you wrote it in the script, for example did you write it in the forms 'onShow ' event or in the body of the script?

You may also have to save the DB name into the Settings.ini as well.

262

(3 replies, posted in General)

There are two projects somewhere  on here that might help you on your way,


Look for POSCALC  and STORE2020.  Unfortunately I can't recall the poster of either of these, but the topic for 2020 was back in March of this year.


Found 2020 http://myvisualdatabase.com/forum/viewtopic.php?id=6077

263

(3 replies, posted in Script)

Well that I didn't know Derek, thanks.

I had a brainwave this morning and realised that I can solve the problem in the SQLQuery.

So I now remove the IF statement altogether and change the query to


SQLQuery('SELECT orderRef FROM orders WHERE orderRef > 0',poRef);

And using your tip of typing the table name into the foreign key property  I placed the "orderRef >0" into the filter property.


The only difference between this and using my code, is that with the code there is no blank (-1) itemIndex and using MVD there is.  picture attached.

I'm trying to fill a combobox manually as the field I need to fill it with  does not have a foreign key.


The code works without the IF statement but fails on <> ''. If I put a space between the two quote marks the program will start.

The reason for the IF statement below is because I don't want the combobox filled with Null values, I only want to see (in this case) a list of  purchase order numbers, so if one does not exist the combobox won't get filled with a space.

procedure frmMain_OnShow (Sender: TObject; Action: string);
var
    poRef: Tdataset;
begin
    
   try
        SQLQuery('SELECT orderRef FROM orders',poRef); {read in the table Orders column OrderRef}
        
        frmMain.cmbOrderRef.Clear; {clear the combobo contents}

        while not poRef.EOF do begin
         if (poRef.FieldByName('orderRef').AsString) <> ' '  then  {check for no PO number in field}
         begin
            frmMain.cmbOrderRef.Items.Add(poRef.FieldByName('OrderRef').AsString);
            poRef.next;
         end;
       end;
    finally
        poRef.close;
        poRef.Free
    end;
.......
.......
.......
end;

Any pointers as to what I'm doing wrong?

265

(1 replies, posted in General)

What actions does this function perform?

Is it similar to posting a record and then change the database mode to dsBrowse and when should it be used?


I've seen script here that uses it and scripts that don;t after SQlexecute code.

Problem has been solved, your answer ehwagner did part of the trick, the rest was solved when I swapped the two variables around so that I was inserting the right bits in the right places.

Thanks for your help Derek and ehwagner.

I would like some help on formatting a SQLExecute statement. I've tried all sorts of variations and this particular field never gets filled no matter what I try  I get a SQL error.


My current code is as below  and this throws a 'constraint error', however reworking this gives me different errors.


The current error is  UPDATE orders SET id_productSupplier = "x" WHERE id = "xx" (x and xx equals a ID number).

procedure frmOrderEntry_btnOrder_OnAfterClick (Sender: TObject);
var
    idx, dbx :string;
begin

     {last database entry ID}
    dbx := intToStr(Last_Insert_id);

    {ID of item in productsupplier}
    idx := intToStr(frmOrderEntry.grdOrder.dbItemID);

    showmessage('dbx '+ dbx + ' idx '+ idx);

     //extract productsupplier ID and insert into orders table
    sqlexecute('UPDATE orders SET id_productSupplier =  "'+dbx+'"  WHERE id = "'+idx+'"');
 
end;

idx and dbx do contain the correct record numbers.

Manually entering the SQL into SQL studio works, but then I'm not using variables in that instance.


Please help, otherwise the cat is only going to have 6 lives left, as his assistance has been of no help at all.

That sounds interesting, I'll take a look. Thanks

I'm such an idiot!! I've found the button, it had somehow moved off the form into invisible space.  How a corruption occurred in the running program and filtered back to the design mode I have no idea. Maybe just a coincidence.


I wish there was a property to lock a component to its position as is possible in Delphi.


Either way I have now found it smile

I have just suffered a weird experience, I clicked on a button to save a record and a DB error appeared (correctly) and now the button has disappeared off the form.

It is still listed in the XML file as visible and shows as visible in the Object Inspector - and yet, on the form it is not!

Any thoughts how I can find it again without having to rewrite code?


<TdbButton Name="btnEditSave" Left="632" Top="472" Width="81" Height="25" dbAnchors="2211" FontName="Segoe UI" FontSize="9" FontColor="8421376" FontStyle="0" TabOrder="5" TabStop="True" dbEnabled="True" dbVisible="True" Cursor="crDefault" BiDiMode="bdLeftToRight" Hint="" ShowHint="False" Caption="Save Edit" dbActionType="adbNone" dbReportOpenIn="rpoPreview" dbExportTo="exptExcel" dbListControls="DBImage1" dbGeneralTable="products" dbSQL="UPDATE productsupplier SET description = "{frmEditPart.edtEditDescription.text}" WHERE id = "{frmEditPart.grdEditPart.sqlValue}";\r\n" dbIconName="Save" dbConfirmDelete="True" dbCloseFormAfterSave="False" dbCheckNotNull="True" dbSortAsc="True" Cancel="False" Default="True" ImageAlignment="iaLeft" Style="bsPushButton" WordWrap="False" Roles="" RoleBtnBehavior="rbbDisabled" RoleMessage="" dbOnClick="frmEditPart_btnEditSave_OnClick"/>

The code below works for single and multiple quotes, but not for speech marks.  I can live with that.

var
s1: String;
begin

 s1 := frmMain.edtDeascription.text;
 s1 := '''' + escape_special_characters(s1) + '''';

sqlexecute('INSERT INTO productSupplier (ID,supplier_part_number,id_suppliers,id_products,description) VALUES ("'+IntToStr(dbid)+'", "'+frmMain.edtSupplierCode.text+'","'+IntToStr(suppID)+'","'+IntToStr(prodID)+'",'S1' )');
    
end;

Thanks Derek,


I'm not sure that will help in this instance as it would need me to create  a list of items that might be entered beforehand which wouldn't work for the 'freehand' entries in a memo box, and, I still need to use a script.


I've just experimented with the Student  Performance  example program, it looks as though the entries are escaped by MVD.


So I need to investigate why that doesn't seem to be the case in my little program. Possibly because I've mixed MVD and script. I shall investigate.

Hi Derek,

I need to be able to enter into  text boxes and a memo box things like 21.5" or "some such" . I see that Dmitry has referenced  several posts with the inbuilt (I assume) function:

SQLexecute('UPDATE some_table SET a_field = '''+escape_special_characters(mainform.editbox1.text)+'''

That of course requires writing the SQL query manually, which I know I do a lot, but just thought where I do use MVD to prepare the SQL query behind the scenes, it would be nice if this function could be accessed in some way.

Ref post: http://myvisualdatabase.com/forum/viewt … 360#p30360

274

(6 replies, posted in General)

Well, there you go, I tried that a couple of times hoping to copy and paste a bunch of components between forms to have the exact same layout, and  it didn't work, so I didn't try it again - I've tried multi-selecting just now after your post and now it works.




I'm sure I'm going senile or something.

I don't have a complete answer to your questions  anakin, but when I used to have a website I used an FTP client to upload to my webhost account.


I'm not a fan personally of the one built into Windows Explorer in Windows10. I think I used to use the free version of CuteFTP.

You will need your log in details that your host will have provided to you. You will need to type in to either Windows Explorer or your ftp client ftp://your_host_address  then enter your user name and password that your host will have given you.


Your host should have told you which folder is the 'published' folder for your website and which is the folder for unpublished pages.  Unpublished pages are ones that are either copies or ones you are using while you design your website.

Whichever folder is your 'live' folder on the host, you will drag and drop your 'index.html' file and any other files just the same as you drag and drop files and folders ib your file manager.