Parent, Self 和 %d, %d [新手]

L3nnon 2010-11-03 01:51:03

implementation
{$R *.dfm}
uses
StdCtrls;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Btn : TButton;
begin
Btn := TButton.Create(Self); {<-- Self 在这段代表什么功能?}
Btn.Parent := Self; {<-- Parent 是什么东东和功能??}
Btn.Left := X;
Btn.Top := Y;
Btn.Width := Btn.Width + 50;
Btn.Caption := Format('Button at %d, %d', [X, Y]); {<---- %d, %d 又是什么?? 可以给实例吗??}

end;
...全文
230 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
L3nnon 2010-12-04
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 snihcel 的回复:]

delphi7.0没有什么详细的书,不过我看到一些delphi5.0的电子书很详细
[/Quote]
可以EMail 我吗?
snihcel 2010-12-03
  • 打赏
  • 举报
回复
delphi7.0没有什么详细的书,不过我看到一些delphi5.0的电子书很详细
L3nnon 2010-12-02
  • 打赏
  • 举报
回复
推推~
求详细和更简单的解析~~

欢迎大家讨论~~
L3nnon 2010-11-17
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 l3nnon 的回复:]

引用 14 楼 ecjtu5208 的回复:

恩。是滴。

谢谢.. 因为只有 D7 的才是最清楚的...
在 2010 易宝龙,很难找到 >.<ll
[/Quote]
推推...
ecjtu5208 2010-11-03
  • 打赏
  • 举报
回复
以下也红色处为d的解释。Decimal十进制。详细见F1

Format specifiers have the following form:

"%" [index ":"] ["-"] [width] ["." prec] type

A format specifier begins with a % character. After the % come the following, in this order:

An optional argument index specifier, [index ":"]
An optional left justification indicator, ["-"]
An optional width specifier, [width]
An optional precision specifier, ["." prec]
The conversion type character, type

The following table summarizes the possible values for type:

d Decimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.
u Unsigned decimal. Similar to 'd' but no sign is output.
e Scientific. The argument must be a floating-point value. The value is converted to a string of the form "-d.ddd...E+ddd". The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point.The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format stringղ default precision of 15 is assumed if no precision specifier is present. The "E" exponent character in the resulting string is always followed by a plus or minus sign and at least three digits.
f Fixed. The argument must be a floating-point value. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative.The number of digits after the decimal point is given by the precision specifier in the format stringղ default of 2 decimal digits is assumed if no precision specifier is present.
g General. The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format stringղ default precision of 15 is assumed if no precision specifier is present.Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses fixed point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format.
n Number. The argument must be a floating-point value. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format corresponds to the "f" format, except that the resulting string contains thousand separators.
m Money. The argument must be a floating-point value. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and CurrencyDecimals global variables, all of which are initialized from the Currency Format in the International section of the Windows Control Panel. If the format string contains a precision specifier, it overrides the value given by the CurrencyDecimals global variable.
p Pointer. The argument must be a pointer value. The value is converted to an 8 character string that represents the pointers value in hexadecimal.
s String. The argument must be a character, a string, or a PChar value. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated.
x Hexadecimal. The argument must be an integer value. The value is converted to a string of hexadecimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has fewer digits, the resulting string is left-padded with zeros.
ecjtu5208 2010-11-03
  • 打赏
  • 举报
回复
1.在本例中的self代表form1对象的指针,create(self)就是你可以不用自己free,在程序关闭的时候会被free,与之区别的还有create(application),create(nil),nil要自己释放

2.parent属性:指定控件的容器。
Btn.Parent := Self;
因为此处Self是指form1,那么这个btn按钮的容器是这个Form1。Btn将显示在Form1上面。
假设,你在Form1上放一个panel1的话,
那么Btn.Parent:=panel1;你会看到,Btn这个按钮将会显示在panel1这个控件上。

3.%d
双击 Btn.Caption := Format('Button at %d, %d', [X, Y]);中的Format,按F1.
以下是说明和例子
format函数说明:
Returns a formatted string assembled from a format string and an array of arguments.

Unit

Sysutils

Category

string formatting routines

function Format(const Format: string; const Args: array of const):
string;

Description

This function formats the series of arguments in the open array Args. Formatting is controlled by the format string Format; the results are returned in the function result as a string.

For information on the format strings, see Format Strings.

format函数例子
This example displays a message on the form's status bar indicating the table's record count after a record is deleted.


procedure TForm1.Table1AfterDelete(DataSet: TDataSet);
begin
StatusBar1.SimpleText := Format('There are now %d records in the table', [DataSet.RecordCount]);
end;


L3nnon 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hongqi162 的回复:]

找本delphi基础的书看看
[/Quote]
我就是看了基础的书才发问..
lhy 2010-11-03
  • 打赏
  • 举报
回复
self就是对象自己
Parent是控件指向父控件的指针
%d是说在这个位置输出一个整数
Frank.WU 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jekhn 的回复:]
另外代码好像少了Btn.Show;你这样会显示吗?
[/Quote]当然会了。。。因为一个可视化的控件默认显示(visible)属性是 true
bdmh 2010-11-03
  • 打赏
  • 举报
回复
去搜搜 format的参数,就明白了
Jekhn 2010-11-03
  • 打赏
  • 举报
回复
在本例中的self代表form1对象的指针,create(self)就是你可以不用自己free,在程序关闭的时候会被free,与之区别的还有create(application),create(nil),nil要自己释放。%d就是输入十进制的整数,具体看format的用法。另外代码好像少了Btn.Show;你这样会显示吗?
coderee 2010-11-03
  • 打赏
  • 举报
回复
有的时候基础比实例更重要。
hongqi162 2010-11-03
  • 打赏
  • 举报
回复
找本delphi基础的书看看
L3nnon 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 ecjtu5208 的回复:]

恩。是滴。
[/Quote]
谢谢.. 因为只有 D7 的才是最清楚的...
在 2010 易宝龙,很难找到 >.<ll
ecjtu5208 2010-11-03
  • 打赏
  • 举报
回复
恩。是滴。
L3nnon 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ecjtu5208 的回复:]
我是按F1之后,乱点了几下,找到的。
[/Quote]
哦... 扎到我了 >.<ll
哈哈... 你用 Delphi 7 吗??
ecjtu5208 2010-11-03
  • 打赏
  • 举报
回复
双击 Btn.Caption := Format('Button at %d, %d', [X, Y]);中的Format,按F1.
选Format function(Visual Component Library Reference)这一项
显示出来后,最下面一行有绿色的Format String,点击它就出来了上面的帮助文字了。
ecjtu5208 2010-11-03
  • 打赏
  • 举报
回复

我是按F1之后,乱点了几下,找到的。
L3nnon 2010-11-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 ecjtu5208 的回复:]

以下也红色处为d的解释。Decimal十进制。详细见F1

Format specifiers have the following form:

"%" [index ":"] ["-"] [width] ["." prec] type

A format specifier begins with a % character. After the % come the follo……
[/Quote]
请问这段内容自那本书??
怎么我找不到的 >.<ll
作者是 : Marco Cantù 吗??

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧