Oh sorry, testsql.show is the name of my form for testing - remove that line.

All that does is display a form I called testsql, you don't need it.

There are three ways that I can think of.


1. Set a button to 'SHOW RECORD'  and make sure you assign the  second combobox to the correct foreign key.


2. Possibly (I haven't tried this), set the first forms combobox as the parent of the second forms combobox.


3. Use script as in the following:


procedure frmEditPart_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
     ShowRecord(frmAddAltSupplier,'productsupplier',frmEditPart.grdEditPart.dbItemID);
    // testsql.show;  do not use this line
end;

The format is  ShowRecord(Form you want the info to show on, table name that contains the data as a string, form and component info is from), in your case that would be the first combobox and it's ID.


For a combobox I think you would put the code in either the 'OnCloseUp' or 'OnChange' even of the originating combobox.



Edited to comment out tstsql.show  - this was something for me that I copied across by mistake.

228

(14 replies, posted in General)

I believe the only way is to make your own form and menu bar.


If you look at K295 website or search here on this forum   vk.com he has a program that would demonstrate a log on program and menu.

I think the program is part of his online course, the complete program is called i18n

229

(14 replies, posted in General)

I don't quite understand what you are looking for.   

Is this a form you have created yourself?

OK, for anyone who wants to be able to delete a folder and files contained within, here is the code I used to get it working. The difficulty was because my folders are 4 folders deep and RemoveDir will not delete folders that are not empty.


Parameter 'F' contains the file path when the function is called.

function DeleteDB(f: string): boolean;
var
 fileDelete :TStringList;  //will contain the list of files in the folder
 filename : string;          // This will be assigned each file name found in the stringlist. 
 indx, cnt: integer;
begin

    result := True;
    fileDelete := TStringList.Create;
    fileDelete.Text := GetFilesList(f, '*.db',True);  //finds all the *.db files in the filepath
    indx :=  fileDelete.Count -1;   // number of files in the folder

   for cnt := 0 to indx  do
   //with filedelete do    -- 'with' will only work if folder is root. As we are 4 folders deep each file in filelist has to become individulised so we have to use a FOR loop

    begin
        filename := filedelete[cnt]; // take each file in the list and assign it to the string one file at a time
        DeleteFile(filename);  //delete the file
    end;

//Once the folder is empty  the directory/folder can now be deleted

    if DirectoryExists(f) then
    begin  
       result := RemoveDir(f);
         //showmessage('Z after delete ' + boolToStr(z));
    end
    else
    begin  //error message we should never get here 
        messageBox('Unable to delete file '+ f, 'Delete File', 0);
        result := False;
    end;

   fileDelete.Free;  // release the stringlist from memory

end;

The calling code

 dtToday := FormatDateTime('dd-mm-yyyy',now);
   dtYesterday := SQLExecute('SELECT dateBackup FROM backups WHERE id = 1'); // note the last date of a backup could be stored in a text file instead of a table

y := ExtractFilePath(application.ExeName);  // y is declared as a string. This gets the folder path of wherever your executable is living

 y := y + 'backup\backup ' + dtYesterday; // filepath to executable + folder 'Backup' + subfolder name = backup + date

if y < b then    // b contains 'today's' date so if the backup date in the database is less than today's date call the delete function
     DeleteDB(y);

Hope that is of some help to somebody

An update.


1. I have solved the date checking by having a backup table with the last date accessed. Read this on opening and then the last directory created can be found no matter how many days have elapsed since running the program.


2. RemoveDir cannot delete a directory when the folder contains files.

Sadly back to the drawing board!   I recoded everything to create and delete folders and then after it was working perfectly, I realised it wasn't practical for weekends or bank holidays, as obviously there would be more than 1 days break.


I think I'll have to go to counting files in the folder and deleting when files in the folder are greater than a number to be decided.


It will give me something to ponder as I wander off to bed.


The mere thought of bed has solved the problem - run a loop in the delete file function incrementing a days prior counter.

So first iteration is Day -1, second is Day-2, third is Day-3, etc.

Они похожи, но, если вы используете dbSQL, вам придется использовать SQLExecute без аргументов для запуска запроса к базе данных.


У Дмитрия или Константина было бы лучшее объяснение. Константин здесь на русском форуме как K245

Я не совсем уверен, но, насколько я знаю, SQLExecute "действие" оператора SQL. dbSQL можно использовать для заполнения таблицы или кнопки для выполнения оператора SQL.

Таким образом, сам SQLExecute работает с базой данных, где dbSQL работает с компонентом, а затем для подключения к базе данных требуется SQLExecute.



I'm not quite sure, but as far as I know, SQLExecute is the "action" of an SQL statement. dbSQL can be used to populate a table or button to execute an SQL statement.

Thus, SQLExecute itself works with the database, where dbSQL works with the component, and then SQLExecute is required to connect to the database.

Good thinking, I'll give it a whirl! Thanks

236

(3 replies, posted in General)

Yes thanks Derek,  I do have both ticked, it is so annoying when it happens because most of the date pickers are 'not visible'.   Maybe that is the problem as it doesn't seem to happen so much with the visible date pickers.


The inexplicable moving of buttons and edit boxes is more of a pain though. It only happens with the components placed on the page control. I think the problem might be as the form is saved some corruption happens which changes the right and bottom settings of the page in the XML file, and  as the page control is not resizeable once laid out it makes it appear that components have moved.


In fact I've just checked using XML Notepad  the page control dimensions have changed between savings.

237

(3 replies, posted in General)

Above result at runtime. As can be seen - unaligned.

Another problem is datetime pickers untick themselves on compile despite setting them to true in the object inspector.

238

(3 replies, posted in General)

I seem to have a problem using a PageControl layed over a panel.

Everytime I compile the project components have a tendency to change their top and left parameters all by themselves.

Sometimes the position settings in the designer are ignored at runtime.

As can be seen below at design time a label is lined up.

какую ошибку ты получаешь сообщение?


Я думаю, тебе нужно сделать это.
Добавить "+"

Пример ниже.


receiveOrder.tgReceiveOrder.dbSQL := 'SELECT DISTINCT suppliers.supplierName,productSupplier.supplier_part_number,productSupplier.description,' +
  'orders.orderQty,orders.receivedDate,orders.receivedQty,products.LineNumber FROM orders ' +
  'LEFT OUTER JOIN suppliers on orders.id_suppliers = suppliers.id LEFT OUTER JOIN productSupplier on orders.id_productSupplier = productSupplier.id ' +
  'LEFT OUTER JOIN products on orders.id_products = products.id WHERE orders.orderRef = "'+receiveOrder.cmbPO.Text+'"';

I have managed to write some code that is successful in deleting backup files, but I had hoped to delete files to a pattern. In this I have failed. I had thought of using the TRIM function, but of course that won't help with the actual names that are on the disk. Perhaps the only answer is to make my own equivalent of the Delphi class TSearchRec which of course is not available in Pascal script.


The files in the backup folder are named as so:


WOS_backup '+ FormatDateTime('dd-mm-yyyy hh-nn-ss',now)+'.db'

The backups occur on opening the program, every 3.5 hours and on close.  My thought was on opening the program a backup is made and then all the files with yesterdays date are deleted. In other words I need the file name to ignore the time content and delete the files with the day before's date.


The code below does not delete any files in the directory.

function DeleteDB(f: string): boolean;
var
    fileDelete : TStringList;
    fileName : string;
    cnt, indx: integer;
    Date : TDateTime;
begin

    result := True;
    fileDelete := TStringList.Create;
    fileDelete.Text := GetFilesList(f, '*.db',False);

    cnt :=  fileDelete.Count -1;
    
    date := Now - 1;
    fileName := DateToStr(date);
    fileName := 'WOS_backup '+ fileName + '*.db';
    
   // Timer.Enabled := False;

    for   indx := 0 to cnt do
      if fileDelete[indx] = filename then  // If I delete this line then all files in the directory get deleted.
        begin
       // DeleteFile(fileDelete[indx]);
        if not DeleteFile(fileDelete[indx]) then
        begin
           messageBox('Unable to delete file '+fileDelete[indx], 'Delete File', 0);
           result := False;
        end; 
     end;


   // Timer.Enabled := True;

   fileDelete.Free;

As noted above, if I remove the code segment if fileDelete[indx] = filename, then it does delete files.  So from a purely academic viewpoint does anyone have any thoughts on a way to ignore the time stamp in the file name?

Thank you in advance for any thoughts.

241

(6 replies, posted in Script)

So using your code:


var S : String ;
begin
     s :=SQLExecute('SELECT Menu1URL2 FROM MainDatabase WHERE id=1');

      DoSomething(s);

end;

procedure DoSomething(request : string);
begin
 
  
   If copy(request, 1,4) = 'HTTP' then    //copy(string, count from where you want to start, how many characters after count)
      OpenURL(request)
   else
       OpenFile( request);

end; 

Looks like while I was typing - Derek was busy uploading!

242

(6 replies, posted in Script)

jeffmtl,


You could test for the condition in an IF statement and then branch to the appropriate code.


So:  UNTESTED!!

ProcedureDoSomething();
var
request : string;  // To hold either URL or File


begin
  
   If copy(request, 1,4) = 'HTTP' then    //copy(string, count from where you want to start, how many characters after count)
      OpenURL(request)
   else
       OpenFile( request);

end; 

Depending on how you are getting the information out of the database, the on or after click event of the button would call ProcedureDoSomething.

OpenFile can open both documents and exe files. 

I don't think Pascal script knows about shellexecute.

243

(6 replies, posted in Script)

For a web page try.

procedure frmMain_lbWebpage_OnClick (Sender: TObject);
var
    webpage:string;
begin
  
  webpage := frmMain.lbWebpage.Caption; 
  OpenURL(webpage);  OR OpenURL('http//:: my website .something') - if website is HTTPS you need to include the 'S'
end;

For a file it depends on what you type of file you want to open, but this will work for text files and exe's.

OpenFile('drive_letter:\your_file_path\your_programe_name');

244

(1 replies, posted in General)

The work-around to the above problem is not entirely satisfactory, but it does the job where a user wants to place the from on a monitor other than their default one from a Windows perspective.


The form must open at the maximum size you want it to be and then it can be moved from screen to screen without it snapping back to the default screen.


I've noticed that the form property Form1.WindowState doens't seem to do much.

245

(1 replies, posted in General)

Is it possible to drag a compiled running program from the default monitor and have it display maximised on a second?


It appears that MVD doesn't have the Screen.Monitor property to either save a previous screen size and position or to persuade it to maximise on any other monitor but the default. Is there another way in MVD?

246

(2 replies, posted in Database applications)

Have a look at the two projects below, they don't use a printer but there is a recent post somewhere in the forum about petrol pumps with a thermal printer.

radsoft trackbook
store2020 Payment

247

(0 replies, posted in General)

Is there a list of the constants that MVD recognises?


I know it doesn't recognise WM_PASTE (sadly).

248

(2 replies, posted in General)

Thanks Derek,


It never occurred to me to use a calculated field. I'll have to study it carefully and think of ways to take the output straight to the email body.

My current incarnation does what I need,  but only if one item is attached to a PO, because the SQL query returns all items that are attached to a PO (which of course is what I want) I have yet to succeed in getting that into the email body.  Hence my thoughts going towards a multi dimensional array.


In an ideal world, if the export to Excel could be persuaded to export directly to an email, I'd be buying the cats expensive food for a week! smile


How did you disable events in your demo program?  I went to fiddle and there is no event tab appearing in the object inspector. Perhaps you are using a different build?

249

(5 replies, posted in General)

I'm not sure about the reports part, but for your forms you could read the contents of your database into a TStringlist or a memobox and then display this on each form.

250

(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.