I didn't see the last post until now, because it went to a new page, but I printed the wiki link and I'll digest it. - Thanks!
After successfully saving a record to stream and back (with a lot of good help), I'm trying to save two records because that's what I'll need for my program. so I made the modified testing program below:
I get these error messages which I'm not sure what they mean:
--------------------------------------
savecrspplrecords.pas(119,34) Error: Operator is not overloaded: "TCrsRecord" * "LongInt"
savecrspplrecords.pas(120,34) Error: Operator is not overloaded: "TPplRecord" * "LongInt"
savecrspplrecords.pas(123,55) Error: Operator is not overloaded: "TCrsRecord" + "TPplRecord"
savecrspplrecords.pas(134) Fatal: There were 3 errors compiling module, stopping
--------------------------------------
unit saveCrsPplrecords;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, math;
type
{ TForm1 }
TCrsRecord = record
code : string[3];
title: string[50];
end;
TPplRecord = record
name: string[20];
choice: string[3];
end;
TCrsRecordArray = array of TCrsRecord;
TPplRecordArray = array of TPplRecord;
TForm1 = class(TForm)
SaveSTREAM: TButton;
GetSTREAM: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure FormCreate(Sender: TObject);
procedure showrecords;
procedure SaveSTREAMClick(Sender: TObject);
procedure SaveAll(const aFileName: string;
const arCrsRecords: array of TCrsRecord;
const arPplRecords: array of TPplRecord);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
arCrsRecords : array[0..2] of TCrsRecord;
arPplRecords : array[0..2] of TPplRecord;
i : integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
arCrsRecords[0].code := 'ORD';
arCrsRecords[0].title := 'Order in Chaos';
arCrsRecords[1].code := 'FBI';
arCrsRecords[1].title := 'History of the FBI';
arCrsRecords[2].code := 'RAN';
arCrsRecords[2].title := 'Randomnes in life';
arPplRecords[0].name := 'Moe';
arPplRecords[0].choice := 'FBI';
arPplRecords[1].name := 'Larry';
arPplRecords[1].choice := 'ORD';
arPplRecords[2].name := 'Curly';
arPplRecords[2].choice := 'ORD';
showrecords();
end;
procedure TForm1.showrecords;
begin
listbox1.items[0] := 'arCrsRecord';
listBox1.items[1] := ' ';
ListBox1.items[2] := arCrsRecords[0].code + ' -- ' + arCrsRecords[0].title;
ListBox1.Items[3] := arCrsRecords[1].code + ' -- ' + arCrsRecords[1].title;;
ListBox1.Items[4] := arCrsRecords[2].code + ' -- ' + arCrsRecords[2].title;;
listbox2.items[0] := 'arPplRecord';
listBox2.items[1] := ' ';
ListBox2.items[2] := arPplRecords[0].name + ' -- ' + arPplRecords[0].choice;
ListBox2.Items[3] := arPplRecords[1].name + ' -- ' + arPplRecords[1].choice;
ListBox2.Items[4] := arpplRecords[2].name + ' -- ' + arPplRecords[2].choice;
end;
procedure TForm1.SaveSTREAMClick(Sender: TObject);
begin
if SaveDialog1.Execute then
Form1.SaveAll(SaveDialog1.FileName, arCrsRecords, arPplRecords);
end;
procedure TForm1.SaveAll(const aFileName : string;
const arCrsRecords: array of TCrsRecord;
const arPplRecords: array of TPplRecord);
var
vFileS : TFileStream = nil;
vTotal : cardinal =0;
begin
vfileS := TFileStream.Create(aFileName, fmOpenReadWrite or fmShareExclusive);
try
vTotal := SizeOf((TCrsRecord)*(High(arCrsRecords)-Low(arCrsRecords))) +
(TPplRecord)*(High(arPplRecords)-Low(arPplRecords));
vFileS.Size := vTotal;
vFileS.Seek(0,0);
vFileS.Write( ( (arCrsRecords[Low(arCrsRecords)]) +
(arpplRecords[Low(arPplRecords)]) ) , vTotal);
finally
vfileS.Free;
end;
end;
end.
I'm not sure if this way of saving two records is possible or not. I found no documentation about handling more than one records.
I'm working on the saving part only at this time.
The ListBoxes are ok at this time, it's just to eventually look at the save/load of the records.
-cl