Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
program GalkaVV;
uses AbsObj,crt;
type
PParamItem=^TParamItem;
TParamItem=record
Name,Value:string;
end;
PParamFifo=^TParamFifo;
TParamFifo=object (TFifo)
{ private
AList,BList:PListItem;
public
constructor Init;
destructor Done;
procedure Put(Element: pointer);
function Get:pointer;}
procedure SetParam(AName,AValue:string);
function GetParam(AName:string):string;
procedure FreeItem(AItem: pointer); virtual;
end;
procedure TParamFifo.FreeItem(AItem: pointer);
var
Tmp:PParamItem;
begin
Tmp:=AItem;
Dispose(Tmp);
end;
procedure TParamFifo.SetParam(AName,AValue:string);
var
Tmp:PParamItem;
begin
New(Tmp);
Tmp^.Name:=AName;
Tmp^.Value:=AValue;
Put(Tmp);
end;
function TParamFifo.GetParam(AName:string):string;
var
TmpList:PListItem;
Tmp:PParamItem;
Str:string;
begin
Tmplist:=AList;
while TmpList<>nil do
begin
Tmp:=TmpList^.Data;
if Tmp=nil then TmpList:=TmpList^.Next
else
if AName<>Tmp^.Name then TmpList:=TmpList^.Next
else
begin
GetParam:=Tmp^.Value;
exit;
end;
end;
if TmpList=nil then GetParam:='';
end;
var
List:PParamFifo;
begin
New(List,Init);
with List^ do
begin
SetParam('Name1','Value4');
SetParam('Name2','Value3');
SetParam('Name3','Value2');
SetParam('Name4','Value1');
writeln(Getparam('Name8'));
writeln(Getparam('Name1'));
writeln(Getparam('Name3'));
end;
Dispose(List,Done);
end.
uses AbsObj,crt;
type
PParamItem=^TParamItem;
TParamItem=record
Name,Value:string;
end;
PParamFifo=^TParamFifo;
TParamFifo=object (TFifo)
{ private
AList,BList:PListItem;
public
constructor Init;
destructor Done;
procedure Put(Element: pointer);
function Get:pointer;}
procedure SetParam(AName,AValue:string);
function GetParam(AName:string):string;
procedure FreeItem(AItem: pointer); virtual;
end;
procedure TParamFifo.FreeItem(AItem: pointer);
var
Tmp:PParamItem;
begin
Tmp:=AItem;
Dispose(Tmp);
end;
procedure TParamFifo.SetParam(AName,AValue:string);
var
Tmp:PParamItem;
begin
New(Tmp);
Tmp^.Name:=AName;
Tmp^.Value:=AValue;
Put(Tmp);
end;
function TParamFifo.GetParam(AName:string):string;
var
TmpList:PListItem;
Tmp:PParamItem;
Str:string;
begin
Tmplist:=AList;
while TmpList<>nil do
begin
Tmp:=TmpList^.Data;
if Tmp=nil then TmpList:=TmpList^.Next
else
if AName<>Tmp^.Name then TmpList:=TmpList^.Next
else
begin
GetParam:=Tmp^.Value;
exit;
end;
end;
if TmpList=nil then GetParam:='';
end;
var
List:PParamFifo;
begin
New(List,Init);
with List^ do
begin
SetParam('Name1','Value4');
SetParam('Name2','Value3');
SetParam('Name3','Value2');
SetParam('Name4','Value1');
writeln(Getparam('Name8'));
writeln(Getparam('Name1'));
writeln(Getparam('Name3'));
end;
Dispose(List,Done);
end.
Соседние файлы в папке Вопросы к экзамену с ответами и демо-программами на Паскале