Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 02/12/23 in all areas

  1. It's OK, a record or helper is just way to add methods for a type, they always work on the instance of the type you call the added method on.
  2. unit Unit2; interface uses System.SysUtils, System.Classes; type TMyHelpToTBytes = record helper for TBytes private function MyGetLen: integer; public property MyLen: integer read MyGetLen; function MyGetBytes(const AStream: TStream; const AStart: integer = 0; ACount: integer = 32): TBytes; function MyBytesAsString: string; end; implementation { TMyHelpToTBytes } function TMyHelpToTBytes.MyGetLen: integer; begin result := Length(Self); end; function TMyHelpToTBytes.MyGetBytes(const AStream: TStream; const AStart: integer = 0; ACount: integer = 32): TBytes; begin result := []; // if (AStream = nil) or {(AStart < 0 ) or} (ACount < 1) then exit; // // maybe some protection here to avoid "AV"...? if ((AStart + ACount) > AStream.Size) then ACount := AStream.Size - AStart; // if ACount > 0 then begin Setlength(result, ACount); // AStream.Position := AStart; AStream.Read(result, ACount); end; end; function TMyHelpToTBytes.MyBytesAsString: string; begin result := ''; // for var B in Self do result := result + ',(' + B.ToString + ')'; // result := result.Remove(0, 1); end; end. uses Unit2; procedure TForm1.Button1Click(Sender: TObject); var MyBytes : TBytes; MyStream: TMemoryStream; begin Memo1.Text := 'MyBytes Len = ' + MyBytes.MyLen.ToString + ', time: ' + TimeToStr(now); // MyStream := TMemoryStream.Create; try MyStream.LoadFromFile('..\..\Unit1.pas'); // MyBytes := MyBytes.MyGetBytes(MyStream, random(100), random(1000)); // Memo1.Lines.Add('MyBytes Len = ' + MyBytes.MyLen.ToString); Memo1.Lines.Add(MyBytes.MyBytesAsString); // MyBytes := MyBytes.MyGetBytes(MyStream, random(100), random(500)); // Memo1.Lines.Add('MyBytes Len = ' + MyBytes.MyLen.ToString); Memo1.Lines.Add(MyBytes.MyBytesAsString); // MyBytes := MyBytes.MyGetBytes(MyStream, random(100), random(1500)); // Memo1.Lines.Add('MyBytes Len = ' + MyBytes.MyLen.ToString); Memo1.Lines.Add(MyBytes.MyBytesAsString); finally MyStream.Free; end; end; initialization ReportMemoryLeaksOnShutdown := true; end.
  3. Uwe Raabe

    Delphi autoformat rules for Attributes

    I am not aware of such a setting. Given that my attributes often are multiline itself, I wouldn't even think of such a behavior, but that is just MHO.
  4. You can download the latest DLLs here: https://github.com/IndySockets/OpenSSL-Binaries and for more info go here: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Securing_Indy_Network_Connections I would change: SSLOptions.Method := sslvTLSv1; to SSLOptions.Method := sslvTLSv1_2;
  5. That is really old version. And that is old deprecated version of TLS. Anything before TLS 1.2 is deprecated.
×