SAY討論區

標題: 『急急,Delphi 功課』Overload,Constructor,Destructor(Delphi 高手請賜教!!) [打印本頁]

作者: frankyhui    時間: 2012-5-12 02:16:12     標題: 『急急,Delphi 功課』Overload,Constructor,Destructor(Delphi 高手請賜教!!)

本人已把 Unit1 链接 Unit2,Unit2 裡有两个函数,而Unit1 有一个自身函数和三个控件。
1 - 关於Overload的问题:
1.1. 如果这样的情况下在Unit2 用Overload 指令对吗?
1.2. 有什麼负面效果?
1.3. 以你的建议,你会怎样以最好的方法使用Overload?

2 - 关於Result:
2.1. Unit2 裡的『function TCon.Runtest: string;』和『function TCon.Runtest(Value: string): string;』
的Result,它们有什麼分别??
2.2. 每个Function 裡是不是都附带着Result(回函值)?
2.3. Result := Value; <--这是什麼,它是什麼时候才出现?
2.4. while j <= 5 do
   begin
   Result := Result + ' ' + IntToStr(j); <--这个 Result(回函值)是不是属於 while?

3 - 关於Unit1 的Button3 自身函数:
3.1. 我要怎样在裡面加入 Constructor 和 Destructor?『请给例子』
3.2. Create 是属於 Constructor 的值吗?
3.3. Free 是属於 Destructor 的值吗?
3.4. 如果不用 Constructor 和 Destructor 会有什麼负面效果出现?<div class="blockcode"><span class="headactions" onclick="copycode($('code0'));">複製內容到剪貼板</span><h5>代碼:</h5><code id="code0">unit Unit2;

interface
uses
SysUtils;

type
TCon = class
private
i, j : Integer;
public
function Runtest : string; overload;
function Runtest(Value : string) : string; overload;

end;

implementation

{ TCon }
function TCon.Runtest: string;
begin
i := 1;
while i &lt;= 4 do
begin
  j := i;
  while j &lt;= 5 do
  begin
  Result := Result + ' ' + IntToStr(j);
  Inc(j);
  end;
Inc(i);
end;
end;

function TCon.Runtest(Value: string): string;
begin
Result := Value;   
i := 1;
while i &lt;= 3 do
begin
  j := i;
  while j &lt;= 5 do
  begin
  Result := Result + ' ' + IntToStr(j);
  Inc(j);
  end;
Inc(i);
end;
end;
end.</code>
作者: a_c_e06    時間: 2012-5-12 03:20:42

3q for 分享
作者: 阿迅    時間: 2012-5-14 05:44:59

樓上的稍等啦
作者: 切雞飯    時間: 2012-5-14 05:44:59

不錯的東西  持續關注




歡迎光臨 SAY討論區 (http://say.go2tutor.com/) Powered by Discuz! X2