unit Unit1;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TCount = class
i, j : Integer;
function Value : string;
end;type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TCount.Value : string;
begin
Result := Value;
i := 1;
while i <= 3 do
begin
j := i;
while j <= 5 do
begin
Result := Result + ' ' + IntToStr(j);
Inc(j);
end;
Inc(i);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
ACount : TCount;
begin
ACount := TCount.Create;
Memo1.Lines.Text := ACount(Edit1.Text); <---问题在这,要怎么改呢??Incompatible Type String..
ACount.Free;
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Button2: TButton;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := Format('当前列:%d, 当前行:%d', [Memo1.CaretPos.X, Memo1.CaretPos.Y]);end;procedure TForm1.Button2Click(Sender: TObject);
var
s: string;
i,sum,e,c,t: Integer;
begin
s := Memo1.Text;
e := 0;
c := 0;
sum := Length(s);for i := 0 to sum do
begin
if (Ord(s[i]) >= 33) and (Ord(s[i]) <= 126) then
begin
Inc(e);
Label2.Caption := '字母数: ' + IntToStr(e);
end; if Ord(s[i]) >= 127 then
begin
Inc(c);
Label3.Caption := '汉字数: ' + IntToStr(c div 2);
end;
end;
end;
end.
其实我想你帮我改正,我所提到的代码。。
我正在的功课是把它分拆为Class,这是我的目的。。
以上的代码我想用Class 包装后,显示“edit1 1 2 3 4 5 2 3 4 5 3 4 5”。。
function TextCount(Value: String): String;
var
i, j: Integer
begin
Result := Value;
i := 1;
while i <= 3 do
begin
j := i;
while j <= 5 do
begin
Result := Result + ' ' + IntToStr(j);
Inc(j);
end;
Inc(i);
end;
end;
begin
i := 1;
while i <= 3 do
begin
j := i;
while j <= 5 do
begin
str:= str+ ' ' + IntToStr(j);
Inc(j);
end;
Inc(i);
end;
Result := str;
end;///////////////////////////////// ACount := TCount.Create;
Memo1.Lines.Text := ACount.RV(Edit1.Text);
ACount.free;
function TCount.Value : string;
begin
Result := ''; //注意这里
i := 1;
while i <= 3 do
begin
j := i;
while j <= 5 do
begin
Result := Result + ' ' + IntToStr(j);
Inc(j);
end;
Inc(i);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ACount : TCount;
begin
ACount := TCount.Create;
Memo1.Lines.Text := edit1.Text + ' ' + ACount.Value;
ACount.Free;
end;
什么意思“注意这里” 为什么要放Result和意味着什么??
当然,纯粹的功能类也有(就是说没有成员只有方法),但是实用性不大,无非就是把相关的操作放在一起便于管理和使用。
你给的例子中的 TCount 即没有对某个数据进行必要的保存,也没有对某种数据类型进行相关的操作,所以用类实现意义不大。如果你一定要用类来实现,那么:
type
TCount = class(TObject)
public
function Value(S: String): String;
end;function TCount.Value(S: String): String;
var
i, j: Integer
begin
Result := Value;
i := 1;
while i <= 3 do
begin
j := i;
while j <= 5 do
begin
Result := Result + ' ' + IntToStr(j);
Inc(j);
end;
Inc(i);
end;
end;......procedure TForm1.Button1Click(Sender: TObject);
var
ACount : TCount;
begin
ACount := TCount.Create;
Memo1.Lines.Text := ACount.Value(Edit1.Text);
ACount.Free;
end;