Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-01

Where to place definition of a record?

8 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi,

I'm following a suggestion for producing my own records so that I can define a custom TStringlist as detailed in this article:
http://dn.codegear.com/article/33423

However, I am unsure of where to post this code and am wondering if someone would advise me.
=================== snip =======================
unit mvlists;

{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils;
type
  TNameValueRecord = record
  private
    FNames: array of string;
    FTypes: array of string;
    function  GetCount: integer; inline;
    function  GetItem(index: integer): string;
    procedure SetItem(index: integer; const Value: string);
  public
    function  Add(const line: string): integer;
    procedure Clear;
    function  IndexOf(const s: string): integer;
    function  ValueOf(const s: string): integer;
    property  Count: integer read GetCount;
    property  Items[index: integer]: string read GetItem write SetItem; default;
  end;
implementation
function TNameValueRecord.Add(const nm, line: string): integer;
begin
  SetLength(FNames,Count+1);
  SetLength(FTypes,Count+1);
  FNames[Count-1] := line;
  FTypes[Count-1] := line;
  result := Count - 1;
end;
procedure TNameValueRecord.Clear;
begin
  SetLength( FNames, 0 );
  SetLength( FTypes, 0 );
.......
=================== snip =======================

I get this error:
mvlists.pas(13,5) Fatal: Syntax error, ":" expected but "identifier FNAMES" found

So I am clearly placing this code in the wrong section.

Reply by email

Michael Van Canneyt
to Dave Coventry
Dave Coventry wrote 21 lines
Hi, I'm following a suggestion for producing my own records so that I can define a custom TStringlist as detailed in this article: http://dn.codegear.com/article/33423 However, I am unsure of where to post this code and am wondering if someone would advise me. =================== snip ======================= unit mvlists; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type TNameValueRecord = record

This should be class, not record.

Michael.

Reply by email

Howard Page-Clark
to Dave Coventry: I'm following a suggestion for producing my own records so that I can define a custom…
Show quoted text 7 lines
I'm following a suggestion for producing my own records so that I can define a custom TStringlist as detailed in this article: http://dn.codegear.com/article/33423 However, I am unsure of where to post this code and am wondering if someone would advise me.

...

Show quoted text 6 lines
type TNameValueRecord = record private FNames: array of string; FTypes: array of string; function GetCount: integer; inline;
... end;

Delphi 2006 introduced new Pascal syntax - the possibility that records can contain methods and properties in addition to the data fields records have always had. This makes such 'advanced records' a sort of pseudo-class construct.
FreePascal/Lazarus does not support this language extension.

----
Howard

Reply by email

Martin Friebe
to Howard Page-Clark
Howard Page-Clark wrote 20 lines
On Sun, 25 Jan 2009 00:22:09 +0200 Dave Coventry wrote: > type > TNameValueRecord = record > private > FNames: array of string; > FTypes: array of string; > function GetCount: integer; inline; > ... end; Delphi 2006 introduced new Pascal syntax - the possibility that records can contain methods and properties in addition to the data fields records have always had. This makes such 'advanced records' a sort of pseudo-class construct. FreePascal/Lazarus does not support this language extension.
try
type
  foo = Object
     a : integer;
     Procedure b;
  end;

Reply by email

Andreas Berger
to Martin Friebe: try type foo = Object a : integer; Procedure b; end;

But unfortunately an object is not totally record compatible. It can not do this:

foo = object
  a : integer
  case boolean of
    true:{...};
    fasle: {...}
  end;
  procedure b;
end;
Martin Friebe wrote 22 lines
try type foo = Object a : integer; Procedure b; end; _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ------------------------------------------------------------------------ Nenhum virus encontrado nessa mensagem recebida. Verificado por AVG - http://www.avgbrasil.com.br Versao: 8.0.176 / Banco de dados de virus: 270.10.13/1914 - Data de Lancamento: 1/24/2009 8:40 PM

Reply by email

Marc Weustink
to Andreas Berger
Andreas Berger wrote 11 lines
But unfortunately an object is not totally record compatible. It can not do this: foo = object a : integer case boolean of true:{...}; fasle: {...} end; procedure b; end;

You cant do this in a record either (if you replace "proc b" by "b: integer") . You need to define a separate type for the union.

Marc

Reply by email