Home > Delphi, Pascal > Read typed file – pascal

Read typed file – pascal

Wednesday, 7 May, 2008 Leave a comment Go to comments

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.

Advertisements
Categories: Delphi, Pascal Tags: , ,
  1. Thursday, 9 April, 2009 at 11:42 pm

    Өте жақсы… Рахмет!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: