Jump to content

Ian Branch

Members
  • Content Count

    1431
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Ian Branch

  1. Ian Branch

    How to get the actual UTC time??

    Hi David, Well I guess that is where I am a little lost. Hmmm. I'm guessing GMT date time doesn't have daylight savings and is therefore effectively UTC time, so I guess the trick would be to source from a GMT clock somehow?? Ian
  2. Ian Branch

    How to get the actual UTC time??

    Hi Wagner, Thank you for your suggestion. My read of "TTimeZone.Local.ToUniversalTime" in the Delphi docs is that it derives the UTC from your Local. This is no good if the time on your local PC is incorrect. This isn't what I am after, I am after the actual UTC date/time. Regards, Ian
  3. Ian Branch

    smtp client in a console app??

    Hi Guys, D10.4.2, latest Indy 10, Win 10. I have created a console app with my Indy code in it. The code is exactly the same as I have in my VCL app, same settings/parameters, etc, which works. But. When I run it in the cmd prompt I get the following error. >>EIdTLSClientTLSHandShakeFailed: SSL negotiation failed.<< Now, I freely acknowledge I probably don't have something set right. 😞 Here is the source I have att.. program DBiPREmail; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, IdMessage, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, IdBaseComponent, IdComponent, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdAttachment, IdMessageParts, IdEMailAddress, IdAttachmentFile, IdGlobal, IdText; // These are all in just to start. To be cleaned up when working.. var dmPREmail: TdmPREmail; IdSMTP: TIdSMTP; IdMessage: TIdMessage; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; // to allow SSL authenticate // try // try // IdSMTP := TIdSMTP.Create(nil); // try // IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(IdSMTP); // IdMessage := TIdMessage.Create(IdSMTP); // // IO HANDLER SETTINGS // with IdSSLIOHandlerSocketOpenSSL1 do begin MaxLineAction := maException; SSLOptions.Method := sslvTLSv1; end; // IdSMTP.Host := 'my smtp email host'; // IdSMTP.Port := 587; // IdSMTP.Username := 'my user name'; IdSMTP.Password := 'my password'; // IdSMTP.IOHandler := IdSSLIOHandlerSocketOpenSSL1; IdSMTP.AuthType := satDefault; // IdSMTP.UseTLS := utUseExplicitTLS; // // SETTING email MESSAGE DATA // IdMessage.Clear; // IdMessage.From.Address := 'my email address'; IdMessage.Recipients.EMailAddresses := 'second email address'; IdMessage.CCList.EMailAddresses := 'third email address'; // IdMessage.Subject := 'Test Email Subject'; IdMessage.Body.text := 'Test Email Body'; IdMessage.Priority := mpHigh; // with TIdText.Create(IdMessage.MessageParts, nil) do begin // Body.text := Body.text + '<p style="color: #5e9ca0;">This is a test <strong>message</strong> for <span style="color: #ff0000;"><strong>emailing</strong></span>.</p><h1 style="color: #5e9ca0;"> </h1>'; ContentType := 'text/html'; end; // IdMessage.ContentType := 'multipart/mixed'; // try IdSMTP.Connect; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Exit; end; end; // try try IdSMTP.Send(IdMessage); finally IdSMTP.Disconnect(); end; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Exit; end; end; // finally // IdSMTP.Free; // end; // except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; // end. Thoughts, suggestions appreciated.. Regards & TIA, Ian
  4. Ian Branch

    smtp client in a console app??

    Doh! Stupid, stupid me! I forgot to put the two .dll files in the project directory. :-( All good now. Thanks Guys, Ian
  5. Hi Team, D10.4.2, Win 10. Something has changed in my IDE and now when I Format Project Source the code is indented by 8 instead of my normal 2. See attached image. I thought this was controlled by the Continuation indent setting of Indentation in the Formatter settings but that hasn't changed. What may have changed/be affecting this please? Regards & TIA, Ian
  6. Ian Branch

    Something's changed in my IDE??

    Ah Ha! Thank you. No wonder I couldn't find it. I was looking in the wrong place. All sorted now. Still to wonder why/how it changed, but all god now. Thanks again, Ian
  7. Ian Branch

    Snap to Grid??

    Hi Team, I am about to start reworking an old project, started in D7, got updated to D2007, now updating to D10. I have Snap to Grid enabled in D10. When I open the old forms, will they automatically snap to their nearest grid points or do I have to do it manually? Regards & TIA, Ian
  8. Ian Branch

    Snap to Grid??

    Ahhh, Thank you. The latter will do nicely. Regards & Tks, Ian
  9. Ian Branch

    Tab Order Confusion..

    Hi Team, I have a form with multiple components on it. They have all been set correctly in their sequence/tab order, which shows correctly in the tab #. Showing the Tab Order, some of the components have grey background tab numbers, and others have green. If I tab from a grey to a green and then tab again, the cursor moves to the next green tab # component rather than the next tab order component. :-( Two questions.. 1. Why; and 2. How do I get hen to physically tab correctly? Regards & TIA, Ian
  10. Ian Branch

    Tab Order Confusion..

    Hi David, 100% correct! Something I never came across before. Something learnt for today. Thanks again. Regards, Ian
  11. Ian Branch

    Physically reduce jpeg image size??

    Hi Kas Ob, I thought I had answered the questions but obviously not adequately. I can read the image from the table and I can write the image back to the table, what I don't know, and yes I would appreciate some code, is how to reduce its size, or 'stretch it down', as you put it. Ian
  12. Ian Branch

    Physically reduce jpeg image size??

    David, VCL, Windows 32bit. The goal is to reduce the physical and therefore stored size. resize or compression, which ever achieves the objective. Cristian, I had considered and even played with an external tool but this has to run on a Client's PC/Server so I would prefer some manner that would be self contained. Ian
  13. Ian Branch

    Error in latest IdIOHandler.

    Just downloaded Indy 10 rev 3902. D10.4.2, Win 10. When building my project I get an error in IdIOHandler.. function TIdIOHandler.ReadInt16(AConvert: Boolean = True): Int16; begin EnsureInputBytes(Self, SizeOf(Int16)); << Error here.. Result := Int16(InputBuffer.ExtractToUInt16(-1, AConvert)); end; The error is.. "[dcc32 Error] IdIOHandler.pas(1285): E2010 Incompatible types: 'Integer' and 'TIdIOHandler'" Regards, Ian
  14. Ian Branch

    Error in latest IdIOHandler.

    Fix Confirmed/Verified. Tks Remy.
  15. Ian Branch

    Return an array from a function??

    Hi Team, I am playing in an area I have no experience in, again. I have the following routine found while googling..... D10.4.2. function RecordToArray(aDataSet: TDataSet); var Data: array of variant; aRecord: array of TVarRec; i: integer; max: integer; begin max := aDataSet.fields.count - 1; // set the lenghth of the arecord array to be the same as the number of // elements in the data array SetLength(arecord, max + 1); SetLength(data, max + 1); // set the variant type pointers to the data array for i := 0 to max do begin arecord[i].VType := vtVariant; arecord[i].VVariant := @data[i]; end; Result := aRecord; end; The objective is to copy the contents of a table row into an array, which is then returned to the calling routine so the table can be closed and the array values accessed throughout the remainder of the program. I want to keep the routine generic so I can use where ever it is convenient. The contents of the fields can be any valid data type. The array can vary in length. The original routine simply took the array and copied it back into the dataset and didn't return anything. I figured, obviously incorrectly, that if 'arecord' is declared as a TVarRec, then the function return should be an Array. Delphi didn't like it. OK. I declared a type of TVarArray = array of variant;, and set the return as TVarArray. Nope, Delphi says I must return a dynamic array. How do I do that please? What should the return type be? Regards & TIA, Ian
  16. Ian Branch

    Return an array from a function??

    All, Thank you for your inputs & suggestions. I have gone with 0x8000FFFF's first suggestion for its simplicity and flexibility. Again, my thanks to all. Regards, Ian
  17. Ian Branch

    What is the difference??

    Hi Team, What is the difference, if any, between.. MyForm := TMyForm.Create(nil); and Application.CreateForm(TMyForm, MyForm) Just curious. Regards & TIA, Ian
  18. Ian Branch

    Round up to next $5

    Hi Team, Given a currency/float value of say 92.12, I need to round it up to the nearest 5.00 point, i.e. 95.00. 123.45 to 125.00, etc. All the roundup routines I can find deal with the decimal component. Does anybody have one that will do what I need? Regards & TIA, Ian
  19. Ian Branch

    Round up to next $5

    Hi Guys, Appreciate the input. The Customer is desiring this.. 100 > 105 101 > 105 102 > 105 103 > 105 104 > 105 105 > 110 106 >110 107 > 110 108 > 110 109 > 110 110 > 115 etc... As best I can tell, ConstantGardner's solution does the job. Ian
  20. Ian Branch

    Round up to next $5

    Thank you. Works perfectly. P.S. I changed the return from Integer to Extended. Regards, Ian
  21. Ian Branch

    Image attachment in a html email??

    Hi Team, D10.4.2, Indy 10. Trying to get an example from the internet working before I try to plug in my own parameters.. unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, Vcl.StdCtrls, IdEMailAddress, IdGlobal, IdAttachment, IdText, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL; type TForm2 = class(TForm) Button1: TButton; IdSMTP1: TIdSMTP; IdMessage1: TIdMessage; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; lSMTP: TIdSMTP; lMessage: TIdMessage; IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; // to allow SSL authenticate // implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var lTextPart: TIdText; lImagePart: TIdAttachment; begin // ... here we need to set required properties for SMTP component. for moe visit How to send Email in Delphi?// lSMTP.Host := 'xxx'; lSMTP.AuthType := satDefault; lSMTP.Username := 'xxxx'; lSMTP.Password := 'xxxx'; lSMTP.Port := 587; lMessage.From.Address := 'yourGmailaddress@gmail.com'; lMessage.Subject := 'My test email with HTML body'; lMessage.Recipients.Add.Address := 'receipent@gmail.com'; lMessage.Body.Clear; // here we have initiated TIdtext object for plain text message in body// lTextPart := TIdText.Create(lMessage.MessageParts); lTextPart.Body.Text := 'This is a plain text message'; lTextPart.ContentType := 'text/plain'; // here we have initiated another TIdtext object for HTML text message in body// lTextPart := TIdText.Create(lMessage.MessageParts); lTextPart.ContentType := 'text/html'; lTextPart.Body.Text := '<html><body><b>Hello World</b><a href="htmlbodyIMG0000.JPG" ></body></html>'; // here we have initiated TIDAttachment object to add image file as attachment to mail as we have use this image in above HTML body message // lImagePart := TIdAttachment.Create(lMessage.MessageParts, 'htmlbodyIMG0000.JPG'); lImagePart.ContentType := 'image/jpg'; lImagePart.Headers.Add('Content-ID: <htmlbodyIMG0000.JPG>'); // if an image is used // // ... write your code to send a message for more visit How to send Email in Delphi? // lSMTP.Connect(); try lSMTP.Send(lMessage); ShowMessage('Email sent'); finally lSMTP.Disconnect(); end; // end; I have the following showing.. The 'note' for TIdAttachment is as follows.. The 'note' for 'htmlbodyIMG0000.JPG' is as follows.. The code is from 2016. Has there been a change around TIdAttachment since? If so, what should the line say/read? Regards & TIA, Ian
  22. Ian Branch

    Image attachment in a html email??

    Hi Lajos, Ahhh. Thank you. Regards, Ian
  23. Ian Branch

    'as' operator??

    Hi Team, I have never knowingly used the 'as' operator and have no idea what it is about and how to use it. I looked at the EMB description of the operator but was none the wiser. So, 1. can somebody point me to a clear explanation of the use of the 'as' operator, preferably with examples, and 2. I have the following code.. pptr := PaPInAddr(phe^.h_addr_list); Which also uses something that I never caught on to as well, pointers. Using Pascal Analyzer, it suggests I should use 'as' somewhere in there. Could someone enlighten me where and why it may be better. Although that insight may come from 1. above. Regards & TIA, Ian
  24. Ian Branch

    nil v self in form create??

    Hi Team, What are the Pros & Cons, and preference, of using Nil v Self in something like.. MyForm := TMyForm.Create(nil); // Nil or self. // try MyForm.ShowModal; finally FreeAndNil(MyForm); end; // Regards & TIA, Ian
  25. Ian Branch

    nil v self in form create??

    Cheers & Tks.
×