Re: Help with a Class, Which is better a TStringList or an arrayof strings
- From: "Bern Rudisill" <bernr@xxxxxxxxxxxxxxxxx dot com>
- Date: 28 Nov 2006 06:57:18 -0700
Thanks for that information, but to be sure I am clean, my class is not
holding a list of Form Objects, Sorry I should of stated this, in this
case forms are actually string like, paper, check, electronic... etc
So for an single in my classs the data could be this
FormGUID = '{G3E5BA5E-97CE-438F-88B9-C705189C07C0}'
FormTypeGUID = '{E4W5BA5E-97CE-438F-89B9-C705189C07C0}'
Form = 'Paper'
DataLevel = 3
NameGUID = '{H3W5BA5E-97CE-438F-88B9-C705189C07C0}'
Does what you wrote still apply?
Bern
"Leonardo M. Ramé" wrote:
Bern, since you are creating a list of forms (in fact, a list of
objects), you can use a TObjectList, its smaller than TStringList and
gives he flexibility you need.
FFormGUID: array of string;
FFormTypeGUID: array of string;
FForm: array of string;
FDataLevel: array of Integer;
FNameGUID: array of string;
You can replace that attributes with a class that contains all of it:
Type
TFormAttrib = class
private
FFormGUID: string;
FFormTypeGUID: string;
FForm: string;
FDataLevel: Integer;
FNameGUID: string;
end;
And add to a TObjectList:
var
myObjectList: TObjectList;
begin
// create the TObjectlist
myObjectList := TObjectList.Create;
// Add TFormAttrib into it
myObjectList.Add(TObject(TFormAttrib.Create));
// Access elements
for I := 0 to myObjectList.Count - 1 do
FormAttrib(myObjectList.Items[I]).FFormGUID := '123123123ASD';
end;
Leonardo M. Ramé
http://leonardorame.blogspot.com
Bern Rudisill escribió:
Hello,
I have created the following class and was wondering if maybe using
TStringList instead of an array of string was better.
Would anyone mind looking at this class and giving any suggestions
on improving it?
Thanks Bern.
unit clsForms; { TForms component. }
interface
uses
Classes;
type
TForms = class(TObject)
private
{ Private declarations }
FFormCount: Integer;
FFormGUID: array of string;
FFormTypeGUID: array of string;
FForm: array of string;
FDataLevel: array of Integer;
FNameGUID: array of string;
function GetCount: Integer;
protected
{ Protected declarations }
function GetFormGUID(ndx: Integer): string; virtual;
procedure SetFormGUID(ndx: Integer; newValue: string); virtual;
function GetFormTypeGUID(ndx: Integer): string; virtual;
procedure SetFormTypeGUID(ndx: Integer; newValue: string);
virtual;
function GetForm(ndx: Integer): string; virtual;
procedure SetForm(ndx: Integer; newValue: string); virtual;
function GetDataLevel(ndx: Integer): Integer; virtual;
procedure SetDataLevel(ndx: Integer; newValue: Integer);
virtual; function GetNameGUID(ndx: Integer): string; virtual;
procedure SetNameGUID(ndx: Integer; newValue: string); virtual;
public
{ Public declarations }
constructor Create;
destructor Destroy; override;
function FormAdd: Integer; virtual;
procedure Clear; virtual;
function GetFormIndex(Form: string): Integer;
procedure GetForms(DrugGUID: string; var tslForms: Tstrings);
virtual;
property Count: Integer read GetCount;
property FormGUID[ndx: Integer]: string read GetFormGUID write
SetFormGUID; { Public }
property FormTypeGUID[ndx: Integer]: string read
GetFormTypeGUID write SetFormTypeGUID; { Public }
property Form[ndx: Integer]: string read GetForm write
SetForm; { Public }
property DataLevel[ndx: Integer]: Integer read GetDataLevel
write SetDataLevel; { Public }
property NameGUID[ndx: Integer]: string read GetNameGUID write
SetNameGUID; { Public }
published
{ Published properties and events }
end; { TForms }
implementation
function TForms.GetFormGUID(ndx: Integer): string;
{ Returns the value of data member FFormGUID[ndx]. }
begin
GetFormGUID := FFormGUID[ndx];
end; { GetFormGUID }
procedure TForms.SetFormGUID(ndx: Integer; newValue: string);
{ Sets data member FFormGUID[ndx] to newValue. }
begin
if FFormGUID[ndx] <> newValue then
begin
FFormGUID[ndx] := newValue;
end;
end; { SetFormGUID }
function TForms.GetFormTypeGUID(ndx: Integer): string;
{ Returns the value of data member FFormTypeGUID[ndx]. }
begin
GetFormTypeGUID := FFormTypeGUID[ndx];
end; { GetFormTypeGUID }
procedure TForms.SetFormTypeGUID(ndx: Integer; newValue: string);
{ Sets data member FFormTypeGUID[ndx] to newValue. }
begin
if FFormTypeGUID[ndx] <> newValue then
begin
FFormTypeGUID[ndx] := newValue;
end;
end; { SetFormTypeGUID }
function TForms.GetForm(ndx: Integer): string;
{ Returns the value of data member FForm[ndx]. }
begin
GetForm := FForm[ndx];
end; { GetForm }
procedure TForms.SetForm(ndx: Integer; newValue: string);
{ Sets data member FForm[ndx] to newValue. }
begin
if FForm[ndx] <> newValue then
begin
FForm[ndx] := newValue;
end;
end; { SetForm }
function TForms.GetDataLevel(ndx: Integer): Integer;
{ Returns the value of data member FDataLevel[ndx]. }
begin
GetDataLevel := FDataLevel[ndx];
end; { GetDataLevel }
procedure TForms.SetDataLevel(ndx: Integer; newValue: Integer);
{ Sets data member FDataLevel[ndx] to newValue. }
begin
if FDataLevel[ndx] <> newValue then
begin
FDataLevel[ndx] := newValue;
end;
end; { SetDataLevel }
function TForms.GetNameGUID(ndx: Integer): string;
{ Returns the value of data member FNameGUID[ndx]. }
begin
GetNameGUID := FNameGUID[ndx];
end; { GetNameGUID }
procedure TForms.SetNameGUID(ndx: Integer; newValue: string);
{ Sets data member FNameGUID[ndx] to newValue. }
begin
if FNameGUID[ndx] <> newValue then
begin
FNameGUID[ndx] := newValue;
end;
end; { SetNameGUID }
function TForms.FormAdd: Integer; { public }
var
intNewCount: integer;
begin
//Increase all the propertie arrays by one
intNewCount := Length(FForm) + 1;
setlength(FFormGUID, intNewCount);
setlength(FFormTypeGUID, intNewCount);
setlength(FForm, intNewCount);
setlength(FDataLevel, intNewCount);
setlength(FNameGUID, intNewCount);
Result := IntNewCount - 1;
end; { FormAdd }
procedure TForms.Clear;
var
intLoop: Integer;
begin
setlength(FFormGUID, 0);
setlength(FFormTypeGUID, 0);
setlength(FForm, 0);
setlength(FDataLevel, 0);
setlength(FNameGUID, 0);
FFormCount := 0;
end; { FromClear }
procedure TForms.GetForms(DrugGUID: string; var tslForms:
Tstrings); { public }
var
intLoop: Integer;
begin
for intLoop := 0 to FFormCount do
if NameGUID[intloop] = DrugGUID then
tslForms.Add(Form[intloop] + '=' + FormGUID[intloop]);
end; { GetForms }
destructor TForms.Destroy;
begin
Clear;
{ Free member variables: }
inherited Destroy;
end; { Destroy }
constructor TForms.Create;
{ Creates an object of type TForms, and initializes properties. }
begin
inherited Create;
FFormCount := 0;
{ Create property fields (that are objects): }
end; { Create }
function TForms.GetCount: Integer;
begin
Result := high(FForm);
end;
function TForms.GetFormIndex(Form: string): Integer;
var
intloop: Integer;
begin
Result := -1;
for intloop := 0 to Self.Count do
begin
if Form[intloop] = Form then
begin
Result := intloop;
exit
end;
end; // for
end;
initialization
finalization
end.
--
.
- Follow-Ups:
- Re: Help with a Class, Which is better a TStringList or an arrayof strings
- From: "Leonardo M. Ramé"
- Re: Help with a Class, Which is better a TStringList or an arrayof strings
- From: Brad White
- Re: Help with a Class, Which is better a TStringList or an arrayof strings
- References:
- Help with a Class, Which is better a TStringList or an array of strings
- From: Bern Rudisill
- Re: Help with a Class, Which is better a TStringList or an array of strings
- From: "Leonardo M. Ramé"
- Help with a Class, Which is better a TStringList or an array of strings
- Prev by Date: Re: Poll: Is it true that Delphi is dead ?
- Next by Date: Re: Please make a new AutoVar Statement
- Previous by thread: Re: Help with a Class, Which is better a TStringList or an array of strings
- Next by thread: Re: Help with a Class, Which is better a TStringList or an arrayof strings
- Index(es):
Relevant Pages
|
|