Jump to content

Search the Community

Showing results for tags 'records'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start




Found 3 results

  1. Delphi 10.4.1 Windows 10 Why does this leak memory? FastMM4 reports A memory block has been leaked. The size is: 36 This block was allocated by thread 0x948, and the stack trace (return addresses) at the time was: 4070A2 [System.pas][System][@GetMem$qqri][4843] 40A0F7 [System.pas][System][@NewUnicodeString$qqri][25659] 40A584 [System.pas][System][@UStrAsg$qqrr20System.UnicodeStringx20System.UnicodeString][26643] 615C6A [Unit1.pas][Unit1][TForm1.GetReminder][65] 616166 [Unit1][Generics.Collections.%TList__1$19Unit1.TReminderItem%.Create] 615A34 [Unit1.pas][Unit1][TForm1.Button1Click][46] 770168CF [GetWindowLongW] 720A55DC [Unknown function at SetWindowSubclass] 4086D3 [System.pas][System][@IsClass$qqrxp14System.TObjectp17System.TMetaClass][18453] 553531 [Vcl.Controls.pas][Vcl.Controls][Controls.TControl.Click][7596] 56C28B [Vcl.StdCtrls.pas][Vcl.StdCtrls][Stdctrls.TCustomButton.Click][5609] type TReminderItem = record public RecordID: Integer; EmployeeID: Integer; EmployeeName: String; HireDate: TDate; LastDate: TDate; Notes: String; procedure Clear; end; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private procedure GetReminder(AList: TList<TReminderItem>); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var LList : TList<TReminderItem>; LReminderItem : TReminderItem; PReminderItem : ^TReminderItem; begin LList := TList<TReminderItem>.Create; try GetReminder(LList); ShowMessage(LList[0].EmployeeName); finally for LReminderItem in LList do LReminderItem.Clear; LList.Free; end; end; procedure TForm1.GetReminder(AList :TList<TReminderItem>); var LReminderItem: ^TReminderItem; begin New(LReminderItem); LReminderItem.RecordID := 1; LReminderItem.EmployeeID := 1; LReminderItem.EmployeeName := 'Test'; LReminderItem.HireDate := Now; LReminderItem.LastDate := Now;; LReminderItem.Notes := 'A Note'; AList.Add(LReminderItem^); end; { TReminderItem } procedure TReminderItem.Clear; begin Self := Default(TReminderItem); end; This is just my latest attempt, I have tried Finalize, FinalizeRecord, FreeMem. The Clear procedure is also an attempt after seeing it in a different post. What is the proper way to free memory of a record I create in a list? Thanks in advance, Gary Unit1.pas Unit1.dfm
  2. I need to serialize and de-serialize different records types. I wrote the following code that works ok only for the serialization and to be honest, I have not tested having records with class objects. The opposite, the de-serialization gives me an error " Internal: Cannot instantiate type .... " when calling the TJson.JsonToObject. I believe it has to do with the initialization of the new object but I can not understand the problem Any ideas? Thank you in advance The code is: type Trec4Json<T>=class private fbv:T; public class Function rec2J(a: T):string; class Function J2rec(const a: string; var c:T):boolean; property bv:T read fbv write fbv; end; implementation uses rest.json; { Trec4Json<T> } class function Trec4Json<T>.rec2J(a: T): string; // Record to Json String var b: Trec4Json<T>; begin b := Trec4Json<T>.create; b.bv := a; try result := TJson.ObjectToJsonString(b); finally b.free; end; end; class function Trec4Json<T>.J2rec(const a: string; var c: T): boolean; // Json String to Record var b: Trec4Json<T>; begin try b := TJson.JsonToObject < Trec4Json < T >> (a); c := b.bv; b.free; result := true; except result := false; end; end;
  3. I have a section of code where I need to modify the top record on a stack. This code is supposed to be highly performant, so I would like to optimize it as much as possible. I would like to get the top record of the stack without popping and pushing it. The record is somewhat complex, so copying the data back and forth to a temporary record is silly. A sample program is below type TMyRec=record s:string; end; PMyRec=^TMyrec; var stk:TStack<TMyRec>; rec:TMyRec; prec:pMyRec; begin stk:=TStack<TMyRec>.Create; rec.s:='Hello'; stk.push(rec); prec:=@stk.Peek; // get error “variable required” prec.s:=’Goodbye’; stk.Free; end; Seems like @stk.Peek is returning the address to the Peek method, not the pointer of the element being returned by the peek method. I have tried casting in various ways but it never compiles properly. Any ideas?