Delphi中预想不到的代码II

王集鹄 2002-08-28 09:06:57
{ No.1 Delphi中的Include文件 }
begin
ShowMessage({$I File1.txt}; //有错吗?
ShowMessage(UpperCase({$I File1.txt});
end;
//新建一个文本文件“File1.txt”、内容填写为:“'Hello Word')”看看

{ No.2 可爱的强制转换 }
var B: Byte
begin
Char(B) := 'A'; //我们通常写 B := Byte('A');
end;

{ No.3 常量表达式的下标 }
Caption := '你'[1] + '好'[2]; //是什么?

{ No.4 脱字号表达的字符 }
Caption := ^:^3^7^!^.^'; //这句可以没有写错
//参考:http://www.csdn.net/Expert/TopicView1.asp?id=658958

{ No.5 非整数类型作下标 }
var A: array[Char] of Byte; //估计很多人都知道

{ No.6 Inc()不只处理整数加一 }
var C: Char;
begin
C := 'A';
Inc(C); //没错吧
end;

{ No.7 "X[:X[:X]]"格式 }
var S: string;
begin
Str(123456.7890:0:2, S); //直接学Delphi的人大多数不会知道
Caption := S;
end;

{ No.8 系统提示、可以好好利用 }
begin
{$MESSAGE HINT '看一看'} //Delphi6适用
end;

{ No.9 with多开几个域 }
with Memo1, DBEdit1, Edit1 do begin
ShowMessage(Text);
ShowMessage(Lines.Text);
ShowMessage(Field.AsString);
end;

{ No.10 Concat连结字符串函数 }
const
cSQLText = Concat(
'SELECT *'#13#10,
'FROM Table1'#13#10,
'WHERE RecId > 100'#13#10);

{ No.11 C里的十六进制 }
var I: Integer;
begin
I := StrToInt('0xA3E'); // 没错,是C里面的0xA3E,而不是Dephi中的$A3E
end;

//-----------------------------------------------------------------------
//新

{ No.12 absoulte子句 }
function f: Char;
var
B: Byte absoulte Result;
begin
B := 97;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
vButton: TButton absoulte Sender;
vForm: TForm absoulte Self;
begin
ShowMessage(vButton.Caption);
ShowNessage(vForm.Caption);
end;

{ No.13 “(.”、“.)”符号 }
//“(.”相当于“[”、“.)”相当于“]”
//不过是我们已习惯“(*”、“*)”,没有习惯“(.”、“.)”
var
I: Integer;
A: array(.0..100.) of Integer;
begin
for I := Low(A) to High(A) do A(.I.) := I;
end;

另外有一个函数我不知道怎么使用 System.TypeOf() 你知道吗?
...全文
47 79 打赏 收藏 转发到动态 举报
写回复
用AI写文章
79 条回复
切换为时间正序
请发表友善的回复…
发表回复
kennidy 2002-09-05
  • 打赏
  • 举报
回复
以上这些除了 No.4 脱字号表达 之外其他的都能找到帮助说明
fz101thoreau 2002-09-04
  • 打赏
  • 举报
回复
奥妙很多,但怎么才知道其所以然?
wangwpf 2002-09-04
  • 打赏
  • 举报
回复
up
johnmack 2002-09-04
  • 打赏
  • 举报
回复
学习
kennidy 2002-09-04
  • 打赏
  • 举报
回复
var

Str: string[32];
StrLen: Byte absolute Str;

有点类似于c里面的union 多个变量内存地址一样
相当于
union
{
char Str[32];
unsigned char StrLen;
}
kennidy 2002-09-04
  • 打赏
  • 举报
回复
$I有帮助说明
Type Parameter
Syntax {$I filename}
{$INCLUDE filename}
Scope Local
Remarks

The $I parameter directive instructs the compiler to include the named file in the compilation. In effect, the file is inserted in the compiled text right after the {$I filename} directive. The default extension for filename is .pas. If filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Directories/Conditionals page of the Project|Options dialog box (or in the directories specified in a -I option on the DCC32 command line).

To specify a filename that includes a space, surround the file name with single quotation marks: {$I 'My file'}.
There is one restriction to the use of include files: An include file can't be specified in the middle of a statement part. In fact, all statements between the begin and end of a statement part must exist in the same source file.
kennidy 2002-09-04
  • 打赏
  • 举报
回复
begin
ShowMessage({$I File1.txt}; //有错吗?
ShowMessage(UpperCase({$I File1.txt});
end;
一个方便的做法 这样可以编译的时候文件内容自动代替
特别是ShowMessage()一个特别大的字符串事后很管用
我想
Edit1.Text = {$I pop.txt}
pop.txt内容可以是 'ABCD.....Z' 呵呵 的确很方便
ylm163net 2002-09-04
  • 打赏
  • 举报
回复
有意思,但是没有用
stdcall 2002-09-04
  • 打赏
  • 举报
回复
认真多!
长弓三石 2002-09-04
  • 打赏
  • 举报
回复
试试看
procedure TForm1.Timer1Timer(Sender: TObject);
begin
caption:=char( random(60)+200) +char( random(60)+200);
end;
王集鹄 2002-09-03
  • 打赏
  • 举报
回复
absoulte ->>>>>>>>>>> absolute //单词拼写错误
ddvboy 2002-09-03
  • 打赏
  • 举报
回复
我也是ABSOULTE不通过
BS 2002-09-03
  • 打赏
  • 举报
回复
No.12 absoulte子句 }
function f: Char;
var
B: Byte absoulte Result;
begin
B := 97;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
vButton: TButton absoulte Sender;
vForm: TForm absoulte Self;
begin
ShowMessage(vButton.Caption);
ShowNessage(vForm.Caption);
end;

//请告诉我absoulte是怎么会事,我测试通不过,谢谢先
beetleking 2002-09-03
  • 打赏
  • 举报
回复
guanzhu a
ddvboy 2002-09-03
  • 打赏
  • 举报
回复
回复人: ihihonline(小小->不要再流浪!!) ( )

能告诉我为什么会这样呢?

还有,
label1.Caption := '我'[1] + '我'[2];
label1.Caption := '我'[2] + '我'[1];

您看看结果,怎么会是这样?
-------------------------------------------
这没有什么的,呵呵
Str = '我'
Str[1]?
ihihonline 2002-09-03
  • 打赏
  • 举报
回复
今天是forget2000的生日
Caption := ^?^&^/^2^'^%^4 + '2000 ' + ^(^!^0^0^9;
有兴趣的话看一看?呵呵
Wnyu 2002-09-03
  • 打赏
  • 举报
回复
好东西!
ihihonline 2002-09-03
  • 打赏
  • 举报
回复
还有,
label1.Caption := '我'[1] + '我'[2];
label1.Caption := '我'[2] + '我'[1];

您看看结果,怎么会是这样?
-------------------------------------------
这没有什么的,呵呵
Str = '我'
Str[1]?
blazingfire 2002-09-03
  • 打赏
  • 举报
回复
好玩
banxian 2002-09-03
  • 打赏
  • 举报
回复
彩蛋语法
加载更多回复(59)

5,939

社区成员

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

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