126

(5 replies, posted in Script)

Hi salahnecibi,



If you have table grid then try something like this.



procedure frmMyForm_grdTableGrid_OnCellClick (Sender: TObject; ACol, ARow: Integer);
var
    id: integer;
begin
   id := (frmMyForm.grdTableGrid.dbItemID); // Get ID

   id := id + 1; //increment ID

// use this if you want to fill the edit box before you do the database search
  frmMyForm.edtEditBox.Text := intToStr(id);  

 // use this if for some reason if you want to keep th eID number for use elswhere in your program
   frmMyForm.edtIDEditBox.Text := sqlExecute('SELECT id FROM TABLE WHERE id="'+intToStr(id)+'"');
end;

If you are not using a table grid then just shout and alternative code can be provided.

127

(4 replies, posted in General)

Papafrankc,


I don't have an answer to your problem but, I think once you have solved the problem your end users will not see this, but each time you compile the program you might have to recheck all your drop down boxes before distributing your program.



As an example my project suffers from two annoyances.


1. A group box and labels keep moving each time I compile the program.
2. My date time pickers like to untick themselves between compilations.

So I have to test to make sure after I have added a new form or script code that these items are reflecting what I want before I recompile.

I suspect your dropdown box problem may well require a similar approach.

128

(4 replies, posted in General)

Is this a PDF link saved in a database?

If it is the following code relies on Windows associating file types and will automatically open the correct program.

procedure frmMain_btnOpenPDF_OnClick (Sender: TObject; var Cancel: boolean);
var
  fName :string;
begin
  fName := SQLExecute('SELECT DISTINCT File_Filename FROM SomeTable WHERE id = '+frmMain.tgTable.SQLValue);
  OpenFile(fName); 


Alternatively if you only ever want to open a PDF file then the above becomes



var
  fName :string;
begin
  fName := SQLExecute('SELECT DISTINCT File_Filename FROM SomeTable WHERE id = '+frmMain.tgTable.SQLValue);
  OpenFile(fName,'AcroRD32.exe'); 

If you are not getting the file name from a database link, just substitute the fName :=  with path and file name of the file you want opened.  Obviously you could add in an OpenDialog if you want the user to search for a file or have an edit box for the user to fill out a name etc.

129

(3 replies, posted in Russian)

Согласно StackOverflow, единственный способ сделать текст в окне сообщения или диалоговом окне сообщения жирным шрифтом - это создать новый класс или создать собственное окно сообщения.


Основные шаги создания такой формы:
1. создать новую форму
2. Добавьте метку и две кнопки
3. Установите для надписи жирный шрифт.
4. добавить обработчик к обеим кнопкам, закрыв форму и установив какое-то свойство, для которого была нажата кнопка.


https://stackoverflow.com/questions/225 … messagebox



According to StackOverflow the only way you can make the text in messagebox or messgedialog bold, is to either create a new class or design your own message box.


The basics steps of creating such a form:
1.Create a new form
2.Add a label and two buttons
3.Set the label font to Bold
4.add handler to both buttons, closing the form and setting some property for which button was pressed.

https://stackoverflow.com/questions/225 … messagebox

Thanks EHWagner,


The code isn't working in Outlook when I tested it today, I just get the HTML as text. However, I discovered a parameter that I will try tomorrow which might just change that.

I read at Microsoft that the oleobject for Outlook includes object.HTMLBody  and I was using object.body.


So, tomorrow when I have access to Outlook, I'll give it a try and see what happens.

131

(10 replies, posted in General)

Hi Kees,


I think Brian means using a file similar to MVD's 'Settings.ini'.

To load a ini file use code similar to:


procedure loadSettings;
var
  settingsIni : TStringlist;
  lngth : integer;
begin
   settingsIni := TStringList.Create;
   settingsIni.LoadFromFile ('Settings.ini');
   dbName := SettingsIni[4];
   SettingsIni.free;
   lngth := Length(dbName) - 7;
   dbName := copy(dbName, 8, lngth);
   FrmMain.lbDbPath.Caption := ExtractFilePath(Application.ExeName)+ dbName;
end;

That code is for loading the standard settings.ini file and finding the name of the database.

To save a file change LoadFromFile to SaveToFile .

132

(31 replies, posted in General)

Papafrankc,

In the code you provided, you haven't assigned the text in your edit box to sKey.

Assuming you have sKey as a string type variable you need -

sKey := formName.EditBoxName.text;

I'm trying to take the contents of a tablegrid and  convert it to HTML for the body of an email.


My problem is that I only seem to get one complete row and the first two columns into the second row into HTML.
I'm practising with a tablegrid that has four columns and five rows.


The code I'm using is below

   sList:TstringList;
begin
         sList:=TStringList.Create;
         sList.Add('<html>');
         sList.Add('<head>');
         sList.add('<style>');
         sList.Add('table, th, td {');
         sList.Add(' border: 1px solid #dddddd; text-align: left; padding: 8px');
         sList.Add('}');
         sList.Add('</style>');
         sList.add('</head>');
         sList.Add('<body>');
         sList.Add('<table>');
         sList.Add('<tr><th>BSuite#:</th>'+ '<th>Part Number</th>' + '<th>Description'+ '</th>'+'<th>Qty'+'</th></tr>');

         for indx := 0 to frmEmail.tgEmailList.RowCount-1 do
         begin
            sList.Add('<tr><td>'+frmEmail.tgEmailList.Cells[0,indx] + '</td>' + '<td>' +frmEmail.tgEmailList.Cells[1,indx] +'</td>'+'<td>'+frmEmail.tgEmailList.Cells[2,indx]+'</td>'+'<td>'+frmEmail.tgEmailList.Cells[3,indx]+'</td></tr>');
         end;
         sList.Add('</table>');
         sList.Add('</body>');
         sList.Add('</html>');

        openURL('mailto:'+frmEmail.cmbEmailAddress.Text+'?subject='+frmEmail.cmbSupplierList.Text+'Order'+'&Body='+sList.text);
sList.Free;

I'm just not seeing why I'm only getting 1 and a bit rows.  This will be going into Outlook, but  my personal email client (emClient) has to have the HTML input manually. My suspicion is that I'm missing an HTML tag, but I can't see where!


Any thoughts gratefully received.

134

(6 replies, posted in General)

Hi Blackpearl8543,


I don't know how to close an MVD program by checking Windows processes as I don't think th ePascal Script allows access to the THandle type.


However, if you have your users 'login' then you can use the following script .


//user_log.pas
var
  logged_in : boolean = False;

procedure ClearLogs;
begin
    SqlExecute('DELETE FROM user_log WHERE username = "' + Application.User.Username + '"');
end;

procedure startLogs;
begin
   If SqlExecute('SELECT count(username) FROM user_log WHERE username = "' + Application.User.Username + '"') > 0 then
     Begin
        MessageBox(Application.User.Username + ' is already logged in.' + #13#10#13#10 + 'If this is not correct, please see your administrator.','Login Problem',MB_OK+MB_ICONERROR);
        frmMain.Close;
     End;
   
   frmMain.lbMainUser.Caption := 'Current User is: ' +Application.User.First_name + ' ' + Application.User.Last_name+'  Role: '+Application.User.Role+'  Last Login: '+DateToStr(Application.User.Last_Login);
   SqlExecute('INSERT INTO user_log (username,Logged_In,isLogged_In) VALUES ("' + Application.User.Username + '","' + FormatDateTime('YYYY-MM-DD hh:nnampm',Application.User.last_login) +'",1)'); 
   logged_in := True;  
end;

procedure frmMain_tgLogged_OnCellDoubleClick (Sender: TObject; ACol, ARow: Integer);
begin
       showmessage(frmMain.tgLogged.Cells[ACol,ARow] +' '+frmMain.tgLogged.sqlValue);
       SqlExecute('Delete FROM user_log WHERE username = "' + frmMain.tgLogged.sqlValue + '"');
end;


begin
end.

You can remove the messagebox code and just go straight to formMain.Close

135

(31 replies, posted in General)

Papafrankc


JB is the man to ask as that is his code snippet.


I'd be wary about saving the serial numbers to a table unless you can encode them (which is possible) as otherwise anyone with copy of SQL Browser or SQL Studio would be able to open the database, read and take your keys.


To save the key to registry all you need is to write:

reg.WriteString('Key', 'sKey');

Assuming that sKey now contains the serial entered via your textbox.

136

(31 replies, posted in General)

papafrankc wrote:

CDB,

So I'm guessing there should be a form called frmNagScreen


Yes


Is there a standard NagScreen form I can use or do I have to create one myself?
Thanks, Frank


You need to create it yourself.  As you are creating the form yourself, you can call it whatever you want, making the appropriate changes in the code to reflect your choice of name.

137

(31 replies, posted in General)

Papafrankc,

I think this needs to be a global constant, so will need to be at the top of the script file, before any procedure or functions.

You can either write:
CONST
   APP_NAME = 'records.exe';

and then in the function   APP_NAME

or

CONST
   APP_NAME = records.exe;

in the nag screen function  'APP_NAME' either should work.


If you copied and pasted JB's code, you might have missed changing some of Jean's frmNagScreen to the name of your own 'nag' forms' name.

PS. Sorry JB I didn't see your reply when I was typing mine.

138

(31 replies, posted in General)

papafrankc,


Did you try substituting APP_NAME  with the actual name of your program, or, make a constant called APP_NAME referring to your program name including the .exe?

A possible but unsatisfactory workaround is to use a try.... except wrap-around.

try
      Outlook := CreateOleObject('Outlook.Application');



    vMailItem := Outlook.GetNamespace('MAPI');

    vMailItem.Logon;
    vMailItem := Outlook.CreateItem(olMailItem);
    vMailItem.Recipients.Add('dibbledabble@somewhere.someplace');
    vMailItem.Subject := 'What a wonderful test email';
    vMailItem.Body := 'This is a test --> how amazing';
    vMailItem.Send;
    Outlook := nil;
    except
     openFile('mailto:?Subject=PURCHASE ORDER PO: 123 &Body= no outlook installed')
 end;

I attempted to use this code suggested by Dmitry -  http://myvisualdatabase.com/forum/viewt … 702#p31702  to determine if Outlook is installed on a users PC.


This fails on two points when compiling.


1.  The type TCLSID  is not recognised.


2. The function CLSIDFromProgID  causes an error 'Undeclared identifier'.


Has this type and function not been included in MVD 6.4, or is there an alternative call?



The code I've written.


function CheckAppInStalled(AValue: String): boolean;
var
    FCLSID: TCLSID;
begin

    Result := (CLSIDFromProgID(PChar(AValue), FCLSID) = S_OK);

end;


procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
const
  olMailItem = 0;
var
  
  Outlook: Variant;
  vMailItem: variant;
begin
 
   if CheckAppInstalled('Outlook.Application') then
   begin
      Outlook := CreateOleObject('Outlook.Application');
   
      vMailItem := Outlook.GetNamespace('MAPI');
      vMailItem.Logon;
      vMailItem := Outlook.CreateItem(olMailItem);
      vMailItem.Recipients.Add('dibbledabble@somewhere.someplace');
      vMailItem.Subject := 'What a wonderful test email';
      vMailItem.Body := 'This is a test --> how amazing';
      vMailItem.Send;
      Outlook := nil;
  end
  else begin  // open non outlook installed client
     openFile('mailto:?Subject=PURCHASE ORDER PO: 123 &Body= no outlook installed')
  end;
end;

141

(5 replies, posted in General)

Hi dbk,

First I should note that using the above code you never see your email message, by that I mean the email is created and sent 'behind the scenes', unlike using mailto: or openfile(mailto:) which opens the email create page.

I don't know the answer to the rest of your question. I do know that the Outlook object has a number of item folders that can be searched such as contacts, calendar, email folders.

This link to Microsoft might help https://docs.microsoft.com/en-us/previo … office.11)

or

http://delphi-kb.blogspot.com/2011/06/o … _6280.html

142

(5 replies, posted in General)

In case anyone else would like to know how to send emails where you can't access the information needed to use the SendMail function, here is how I've managed to send an email using Outlook.

This code has been scrounged from StackOverflow where it was scrounged from somewhere else.

procedure Form1_SendEmail_OnClick (Sender: TObject; var Cancel: boolean);
const
  objMailItem = 0;
var
  OKToUse: boolean;
  Outlook: Variant;
  vMailItem: variant;
begin
 // OKToUse := false;


      Outlook := CreateOleObject('Outlook.Application');
    
    vMailItem := Outlook.GetNamespace('MAPI');
    vMailItem.Logon;  {[color=blue]this allows an email to be sent if Outlook is not open at the time of sending[/color]}
    vMailItem := Outlook.CreateItem(objMailItem);
    vMailItem.Recipients.Add('someperson@someplace.something');
    vMailItem.Subject := 'What a wonderful test email'; {[color=blue]this could be a text box with the string contained in it[/color]}
    vMailItem.Body := 'another string or stringlist with the body text';
    vMailItem.Send;
  

  Outlook := nil;  {[color=blue]free the object - this might not be necessary, some sources say it automatically frees when out of scope[/color]}
end;

143

(2 replies, posted in General)

Would this help?

Ignore the SQL, you don't need to do that, the trick is in using MessageDlg function which has both button options and a message capability.

procedure frmEditOrderQty_btnFrmAmendDeleteRecord_OnClick (Sender: TObject; var Cancel: boolean);
 var
 text : string;
 btn :integer;
begin

  
   text := 'ORDER ITEM '+#13#13 + frmEditOrderQty.edtfrmAmendDescription.Text +'  x '+ frmEditOrderQty.edtNewQty.Text;

   btn := messageDlg('CONFIRM DELETION OF '+text,mtWarning, mbCancel+mbOK, 0);

   if  btn  = mrCancel then
      Exit
   else
     begin
       SQLExecute('DELETE FROM orders WHERE orders.id =  "'+ intToStr(frmMain.tgOrders.dbItemID) +'"');
       ShowMessage(#13#13 + text + ' has been DELETED' );
       frmMain.tgOrders.dbupdate
      end;

 // frmEditOrderQty.Enabled := True;

  frmEditOrderQty.Close;

end;

For other MessageDlg options see http://www.delphibasics.co.uk/RTL.asp?Name=messagedlg

I have a need to take selected items from a table grid and place them in the body of an email.

The code below using a stringlist works to an extent, however whilst my test 'showMessage' does show what I want, by the time it gets to an email body only the first two items ever show.

I could copy to clipboard and then manually paste into the email body, but that is unsatisfactory as I hope to make this automatic with the user only having to press 'send' in their email client.

My current code is

procedure frmEmail_SendEmail_OnClick (Sender: TObject; var Cancel: boolean);
const

  CRFL = #13#10;
var
  emailList : TStringlist;

  indx,colmn : integer;

begin
     emailList:= TStringList.Create;
     emailList.Clear;

     for indx := 0 to frmEmail.tbgEmailList.RowCount -1  do
     begin

         for colmn := 0 to frmEmail.tbgEmailList.Columns.Count -1 do
        begin
         emailList.add(frmEmail.tbgEmailList.Cells[colmn,indx]);

        end;
        emailList.add(CRFL);
     end;
    // try

        //st := clipboardGet;


      openURL('mailto:'+frmEmail.cmbEmailAddress.Text+'?Subject='+frmEmail.cmbSupplierList.Text+' Order'+'&Body='+ emailList.text);
      emailList.free;
     // SQLExecute('UPDATE orders SET orderEmailed = 1 WHERE orders.id =');
end;
jean.brezhonek wrote:

Hello abu7akm

Neither for the web
JB

Hi Jean,


Are you sure about that?  Under the menu item 'Project' there is the Webgrid option, which makes for a very basic web based program. It requires mySql as the database.

A link to a demonstration page  http://myvisualdatabase.com/webgrid_rus/

This works for me, I have it in the button_OnAfterClick event.

У меня это работает, у меня это в событии button_OnAfterClick

procedure Form1.............
var
count, indx : integer;

count := Form1.edGrid.RowCount -1;

for indx := 0 to count do
begin
     if Form1.edGrid.Selected[indx] then
     begin
           your edit code here
      
     end;
end; 

147

(0 replies, posted in General)

If your browser has a language translate function, I can recommend MVDs Russian language help webpage. I find it more helpful than the current English language one.

The link is http://myvisualdatabase.com/doc_ru/ 


I've attached an example that my browser has converted to English as a demonstration.

Думаю в винде не работает. Я могу ошибаться

I think in Windows it doesn't work. I might be mistaken

vit007


You used Form1.TableGrid1.CELL[0,i], the example code used Form1.TableGrid1.CELLS[0,i] - important difference.


Вы использовали Form1.TableGrid1.CELL[0, i], в примере кода использовалась Form1.TableGrid1. CELLS[0, i] - важное отличие.

abu7akm wrote:

What is the programming language used in script?

Pascal