[Lazarus] How write a proper Type declaration with procedures?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] How write a proper Type declaration with procedures?

Joe Shepherd
Hi
 
I have inherited a boon-doggle of a system, about 60% of which is in an old version of Delphi. I hope to use Lazarus/Free Pascal to re-implement for Windows , with a mySQL back-end on a Linux box.
 
This isn't real code, but a minimal example of what I want to do in a unit:
 
 TURLTable=class(TStringlist)
    private
       property Table: LinkArray;
    public
       procedure Insert(const s: string);
    end;
 
elsewhere I will have
 
var
   SpecTab: TURLTable;
....
 
SpecTable.Insert(some string')
 
When I come to write the implementation part of the unit, what's the syntax to refer to the property Table? If I use
 
procedure TURLTable.Insert(const s: String);
 
begin
   Table[1] := s
end;
 
I get the error 'No member is provided to access property.'
 
How can I acess private properties like this?
 
Sorry if this is naiveI've become involved in something that I really didn't anticipate.
 
Joe
-------------------
Perth, WA, Australia
 

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How write a proper Type declaration with procedures?

leledumbo
Administrator
> When I come to write the implementation part of the unit, what's the syntax to refer to the property Table? If I use
> ...
> I get the error 'No member is provided to access property.'

That should be correct. It's something else that bugs. At least the following compiles for me:

unit Simple;

{$mode objfpc}{$H+}

interface

uses
  Classes;

type
  TURLTable = class(TStringList)
  private
    Table: array of String;
  public
    procedure Insert(const s: String); overload;
  end;

implementation

procedure TURLTable.Insert(const s: String);
var
  i: Integer;
begin
  i := Length(Table);
  SetLength(Table,i + 1);
  Table[i] := s;
end;

end.
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How write a proper Type declaration with procedures?

Anthony Walter
In reply to this post by Joe Shepherd
type
  TURLTable = class(TStringlist)
  private
    FTable: LinkArray;
    function GetTable: LinkArray;
  public
     procedure Insert(const s: string);
     property Table: LinkArray read GetTable;
  end;
 
function TURLTable.GetTable: LinkArray;
begin
  Result := FTable;
end;

procedure TURLTable.Insert(const s: string);
begin
end;

... or alternately

  property Table: LinkArray read FTable;


... and remove function GetTable: LinkArray;

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How write a proper Type declaration with procedures?

Joe Shepherd
Thank you both - another case of not seeing the wood for the trees.
 
Joe
 
 
 

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus