Jump to content

Virgo

Members
  • Content Count

    86
  • Joined

  • Last visited

Posts posted by Virgo


  1. Unfortunately I do not have Delphi version new enough. But maybe there is an overloaded version, that allows required parameters?

    Indy own TIdSocketHandle.SetScokOpot also has AOptVal:Integer... But GStack.SetSocketOption seems to have required version.


  2. 2 minutes ago, David Heffernan said:

    I mean I hope you aren't proposing AnsiString as a place to hold bytes. 

    What I ment was, that I got an impression, that SHA1ofStr and Base64Encode functions were originally written for pre-Unicode Delphi. And to make them work on Unicode Delphi version String was just replaced with AnsiString.  And on old Delphi versions it was usual to use string as byte buffer. Event Delphi itself did it.


  3. 3 hours ago, grantful said:
    
    procedure SendTestEmail2; 
    var 
      SMTP: TIdSMTP;
      Message: TIdMessage;
      SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
    begin 
      SMTP := TIdSMTP.Create(nil); 
      Message := TIdMessage.Create(nil); 
      //SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); 
      SSLHandler.SSLOptions.Method := sslvTLSv1_2; // or sslvTLSv1, sslvTLSv1_1, etc.

     

    SSLHandler variable is not initialized... So Access Violation is mandatory.


  4. 9 minutes ago, programmerdelphi2k said:

    @hoaque  my tip is look at https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Installation_Notes

    as your Windows is not installed yet, then, can be the "cause" etc.. 

    Which part of this would apply to sample program in original post? Windows 8.1 is not listed as supported platform, but if Windows 7 is supported, then that should not be an issue. And if it works Windows 10 PE, then that makes it unlikely, that it uses something like AVX. Although, compiling it with all optimizations off would be something to try. Other thing would be to remove SysUtils usage... Just in case, that it is something in SysUtils initialization. As I understand, problem is not with IDE but with statically linked command line program, that only uses System and SysUtils units.

     

     

    • Thanks 1

  5. 9 hours ago, Willicious said:

    t's the idea of instances-of-classes that keeps catching me out. If a class is defined somewhere, it should be callable as that class. Why do I have to redefine/redeclare it in a different unit? Why not this instead:

    Unit 1
        Class1

              PropertyA

     

    Unit 2

        uses

             Class1

     

    if Class1.PropertyA etc...

    What kind of programming languages have you actually used before? Because you would have same issues in most languages... Event in javascript or python you need an instance to actually use it.

    • Like 1

  6. 2 hours ago, Remy Lebeau said:

    If the Owner form assigns itself as the actual Owner (from the RTL's perspective) of the Child form, then the RTL will handle all of that for you automatically.  All you would have to do in your own code is have the Owner form override the Notification() method.

     

    However, personally, I would just have the Owner form assign its own handlers to the Child form's OnClose and OnDestroy events instead.  That way, the Owner, not the Child, decides whether or not to set Action=caFree in the OnClose event, and the Owner can still react to the Child being destroyed without having to override the Notification() method.

    Right... Actually with owner set only overriding notification is needed... 

    And assigning OnClose and OnDestroy from owner form is probably simpler idea.. with assigned OnDestroy clearing handles instead Notification. I mean we actually use OnDestroy to clear global form variables in form units, when form is free (with check, if Self is same as variable).


  7. ChildForm sest Action to caFree on OnClose event handler

    Owner  calls FreeNotification(ChildForm) after creating the childform.

    Owner overrides Notification() and when it receives notification, that childform is freed, then sets variable to nil (or whatever needs to be done).

    Owner calls RemoveFreeNotification(ChildForm) when it is going to manually free childform or when owner itself is going to be freed.

    • Like 1
    • Thanks 1

  8. 11 minutes ago, Fr0sT.Brutal said:

    it has: `%10d`

     

    I somehow managed to miss width parameter. With it it is really possible to rewrite WriteStr as format and since Delphi does not have WriteStr, it is best solution. Better than trying to hack around with file.

    So:

    s2 := format('x = %10.4f, y = %10d, s = %20s', [x, y, s]);

    would be same as

    WriteStr(s2, 'x = ', x:10:4, ', y = ', y:10, ', s = ', s:20);

     


  9. 33 minutes ago, Sherlock said:

    Hmm almost sounds like a job for TWriter.WriteString which writes to a TStream. If you don't want it to be a file, it could be a TStringStream.

    No it is not. TWriter.WriteString writes strings.

    example:
     

    program writeStrTest;
    {$mode objfpc}
    {$H+}
    var
      x: extended;
      y: Int64;
      s, s2: string;
    begin
      x := 193.17;
      y := 123746214;
      s := 'Some tekst';
      WriteStr(s2, 'x = ', x:10:4, ', y = ', y:10, ', s = ', s:20);
      WriteLn(s2);
    end.

    will output

    x =   193.1700, y =  123746214, s =           Some tekst

     

    format is closest thing in Delphi, but format does not have ability to pad values with spaces (if user requires it).

     

     


  10. Sample for doing same thing with Synapse THTTPSend:
     

    procedure TestPost;
    var
      H: THTTPSend;
      S: UTF8String;
      Res: Boolean;
    begin
      H := THTTPSend.Create;
      try
        S := '{"recipient":"testing@checkbook.io","name":"Widgets Inc.","amount":5,"description":"Test Payment"}';
        H.MimeType := 'application/json'; //synapse has separate propery for content-type header
        H.Headers.Add('accept: application/json');
        H.Headers.Add('Authorization: XXXXX');
        H.Document.Write(S[1], Length(S)); 
        Res := H.HTTPMethod('POST', 'https://demo.checkbook.io/v3/check/digital');
        if Res then
        begin
          SetLength(S, H.Document.Size);
          if H.Document.Size > 0 then
            H.Document.Read(S[1], H.Document.Size);
          ShowMessage(format('%d: %s', [H.ResultCode, S]));
        end
        else
          ShowMessage(H.Sock.LastErrorDesc);
      finally
        H.Free;
      end;
    end;

    ends with

    400: {"error":"Invalid authorization header"}

     

    Because sample XXXXX authorization header is not correct obviously....

    • Thanks 1
×