Read typed file - pascal

7 05 2008

File structure in C++

typedef struct TAGRECORD
{
char DeviceName[50]; // Имяприбора
char TagName[10]; // Имяпараметра
char TagValue[50]; // Значение
time_t TagTime; // Время записи
int TagChannel; // Канал
int TagInfo; // 0 - info, 1 - control
} TAGRECORD,*LPTAGRECORD;

Read it with Pascal?

Solution >>>

unit Unit2;
interfaceuses… ComCtrls, … DateUtils…;type
PtargetFile = ^TFile;
TFile = record
DeviceName: array[0..49] of Char; // Имяприбора
TagName: array[0..9] of Char; // Имяпараметра
TagValue: array[0..49] of Char; // Значение
TagTime: integer; // Время записи
TagChannel:integer; // Канал
TagInfo:integer; // 0 - info, 1 - control
end;TMainForm = class(TForm)

procedure LoadFile(const _s_FName:string);
….
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
targetFile:PtargetFile;
fFile: file of TFile;
implementation
{$R *.dfm}
….
procedure TMainForm.LoadFile(const _s_FName:string);
var
ListItem: TListItem;
i,n:word;
begin
ListView.Items.Clear;
if FileExists(_s_FName) then
begin
AssignFile(fFile,_s_FName);
Reset(fFile);
n:=0;
while not Eof(fFile) do
Begin
Application.ProcessMessages;
targetFile := new(PtargetFile);
Read(fFile,targetFile^);
ListItem:= ListView.Items.Add;
ListItem.Data:= targetFile;
ListItem.Caption:=targetFile.DeviceName;
ListItem.SubItems.Add(targetFile.TagName);
ListItem.SubItems.Add(targetFile.TagValue);
try
ListItem.SubItems.Add(FormatDateTime(’dd.mm.yy hh:mm:ss’,UnixToDateTime(targetFile.TagTime)));
Except
Continue;
end;
ListItem.SubItems.Add(IntToStr(targetFile.TagChannel));
ListItem.SubItems.Add(IntToStr(targetFile.TagInfo));
n:=n+1;
Seek(fFile,N);
end;
CloseFile(fFile);
Caption:=’Record count: ‘+inttostr(n);
end;
end;

end.


Actions

Information

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>