转贴:不是我写的!可以用以下的方法声明一个类: type MyClass = class Name: integer; Age: string; public function GetName: string; procedure SetName(strName: string);
function GetAge: integer; procedure SetAge(iAge: integer); end;定义类的方法: procedure SetName(strName: string); begin Name := strName; end;function GetName: string; begin Result := Name; end;procedure SetName(iAge: integer); begin Age := iAge; end;function GetName: string; begin Result := Age; end; 可以用以下的方法对类中声明的方法进行调用: procedure Button1.click(sender: Tobject); begin MyClass.SetName('Tom'); Edit1.Text := MyClass.GetName; MyClass.SetAge(23); Edit2.text := IntToStr(GetAge); end;
to Top hotzhu(非洲白脸) 我当然自己要使用堆栈,我以前使用堆栈就是用数组或string型变量代替的,为了象堆栈一样 先进后出使,还得把string的内容倒过来.很麻烦.而且delphi老提示[Warning] byyl.pas(180): Unsafe code 'String index to var param' 我想delphi因该有专门的东东处理堆栈. 你说"C的基础课程里就有",有什么?delphi书上不就介绍delphi怎么安装,面版怎么使用(贵的书我买不起,学校图书馆里又借不到).找的到的话,我就不发帖子问了. 欢迎您:symbol68688 可用分:1279 总信誉分:100 注销我的登录 .三角裤一条,100分的帖子还能发12个. 希望多多回帖!
我写的堆栈: str:string jsq:integer 压栈a:str:=str+'a' ; jsq:=jsq+1 压栈b:str:=str+'b' ; jsq:=jsq+1 弹栈:jsq:=jsq-1; 取栈顶字符:str[jsq] 再压栈c:str[jsq+1]:=c ;jsq:=jsq+1 可以做出来,但我总觉得不好,delphi也会提示: Unsafe code 'String index to var param' 想请教各位老大怎么写的?
发送者 hotzhu的留言: 记录,保存,留念function MyStach.pop(var str : string) : boolean; begin str := ''; result := false; if FList.Count = 0 then exit; str := FList[Flist.Count - 1]; FList.Delete(Flist.Count - 1); Result := true; 接上一部分 end; destructor MyStach.Destroy; begin FList.Free; inherited; end; end. 调用:a := MyStach.Create ;a.push(‘阿’); if a.pop(str) then Memo2.Lines.Add(str) else Memo2.Lines.add('列表中没有值'); a.Free; 编号: 12 发送者 hotzhu 发送时间 2003-6-5 20:33:45 删除 回复 内容 type MyStach = class private Flist : TSTringList; public constructor Create; procedure push(str : string); function pop(var str : string) : boolean; destructor Destroy; //override; end; implementation constructor MyStach.Create; begin inherited; Flist := TSTringList.Create ; end; procedure MyStach.push(str : string); begin Flist.Add(str); end;
2.你是指操作系统怎么使用堆栈还是delphi编译器使用堆栈还是自己要使用堆栈 ?
自己使用可以写一个, C的基础课程里就有. 系统怎么搞我就不知道了.
.....至于堆栈,用汇编吗???
asm
....中定义建议多看看书
type MyClass = class
Name: integer;
Age: string;
public
function GetName: string;
procedure SetName(strName: string);
function GetAge: integer;
procedure SetAge(iAge: integer);
end;定义类的方法:
procedure SetName(strName: string);
begin
Name := strName;
end;function GetName: string;
begin
Result := Name;
end;procedure SetName(iAge: integer);
begin
Age := iAge;
end;function GetName: string;
begin
Result := Age;
end;
可以用以下的方法对类中声明的方法进行调用:
procedure Button1.click(sender: Tobject);
begin
MyClass.SetName('Tom');
Edit1.Text := MyClass.GetName; MyClass.SetAge(23);
Edit2.text := IntToStr(GetAge);
end;
hotzhu(非洲白脸)
我当然自己要使用堆栈,我以前使用堆栈就是用数组或string型变量代替的,为了象堆栈一样
先进后出使,还得把string的内容倒过来.很麻烦.而且delphi老提示[Warning] byyl.pas(180): Unsafe code 'String index to var param' 我想delphi因该有专门的东东处理堆栈.
你说"C的基础课程里就有",有什么?delphi书上不就介绍delphi怎么安装,面版怎么使用(贵的书我买不起,学校图书馆里又借不到).找的到的话,我就不发帖子问了. 欢迎您:symbol68688 可用分:1279 总信誉分:100 注销我的登录 .三角裤一条,100分的帖子还能发12个. 希望多多回帖!
str:string
jsq:integer
压栈a:str:=str+'a' ; jsq:=jsq+1
压栈b:str:=str+'b' ; jsq:=jsq+1
弹栈:jsq:=jsq-1;
取栈顶字符:str[jsq]
再压栈c:str[jsq+1]:=c ;jsq:=jsq+1
可以做出来,但我总觉得不好,delphi也会提示: Unsafe code 'String index to var param'
想请教各位老大怎么写的?
begin
str := '';
result := false;
if FList.Count = 0 then exit;
str := FList[Flist.Count - 1];
FList.Delete(Flist.Count - 1);
Result := true;
接上一部分
end;
destructor MyStach.Destroy;
begin
FList.Free;
inherited;
end;
end.
调用:a := MyStach.Create ;a.push(‘阿’);
if a.pop(str) then
Memo2.Lines.Add(str)
else
Memo2.Lines.add('列表中没有值');
a.Free;
编号: 12 发送者 hotzhu 发送时间 2003-6-5 20:33:45 删除 回复
内容 type
MyStach = class
private
Flist : TSTringList;
public
constructor Create;
procedure push(str : string);
function pop(var str : string) : boolean;
destructor Destroy; //override;
end;
implementation
constructor MyStach.Create;
begin
inherited; Flist := TSTringList.Create ;
end;
procedure MyStach.push(str : string);
begin
Flist.Add(str);
end;
编号: 11 发送者 hotzhu 发送时间 2003-6-5 20:27:13 删除 回复
内容 刚看到你的揭帖。
Delphi也堆栈可以用TStringList实现。
刚随便写了一个, 如果要可以发给你,几十行代码,还包括测试在内。