Solved

Variable RecordTypes as parameter for procedures

Posted on 1998-11-08
2
189 Views
Last Modified: 2010-04-04
Is it anyway possible to have different/variable RecordTypes as input parameter for procedures?

Lets say I wanted to make a standard procedure for reading/writing records to 'files of recordtypes', is that possible like this or is there an easier way?
0
Comment
Question by:smitje
2 Comments
 
LVL 1

Accepted Solution

by:
ow earned 100 total points
ID: 1346123
 Hi smitje,

it is possible, to use variable record types as input parameter, but as you normaly need to know the size of the records, this must be delivered too.
Here is an example:

function WriteData (var F :file; var Data; Count :integer) :boolean;
  var
    AmtTransferred :integer;
  begin
  BlockWrite(F, Data, Count, AmtTransferred);
  Result := (AmtTransferred = Count);
  end;

procedure CreateDataFile1;
  type
    tDataRec = record
      N :integer;
      S :string[5];
      end;
  var
    F :file;
    DataRec :tDataRec;
  begin
  AssignFile(F, 'test.dat');
  Rewrite(F, 1);
  DataRec.N := 1;
  DataRec.S := 'text';
  if WriteData(F, DataRec, SizeOf(DataRec)) then
    WriteLn('Ok')
  else
    WriteLn('Error');
  CloseFile(F);
  end;

I would prefer streams, to do this work:

procedure CreateData2;
  type
    tDataRec = record
      N :integer;
      S :string[5];
      end;
  var
    FileStream :tFileStream;
    DataRec :tDataRec;
  begin
  FileStream := tFileStream.Create('test.dat', fmCreate);
  DataRec.N := 1;
  DataRec.S := 'text';
  if (FileStream.Write(DataRec, SizeOf(DataRec)) = SizeOf(DataRec)) then
    WriteLn('Ok')
  else
    WriteLn('Error');
  FileStream.Free;
  end;


Regards
  ow
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346124
Hello Y'all...

This couple of lines...

if (FileStream.Write(DataRec, SizeOf(DataRec)) = SizeOf(DataRec)) then
       WriteLn('Ok')
     else
       WriteLn('Error');

should be as follows,,,,

if (FileStream.Write(DataRec, SizeOf(DataRec)) = SizeOf(DataRec)) then
       WriteLn(F, 'Ok')
     else
       WriteLn(F, 'Error');

Cheers,
Viktor
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 195
Strange behavior when a form is closed 6 61
can't find the executable in Simulator 1 101
Find and Replace Stream with 0s 8 69
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question