括号匹配(delphi)-转
type
TCharStack = class(TStack)
private
function GetTop: Char;
public
function Pop: Char;
function Push(Item: Char): Char;
property Top: Char read GetTop;
end;
const
FindSet = ['(',')'];
implementation
{$R *.dfm}
{ TCharStack }
function TCharStack.GetTop: Char;
begin
Result := Char(Peek);
end;
function TCharStack.Pop: Char;
begin
Result := Char(inherited Pop);
end;
function TCharStack.Push(Item: Char): Char;
begin
Result := Char(inherited Push(Pointer(Item)));
end;
function FindFirstOf(const Str: String; const CharSet: TSysCharSet; StartPos: Integer = 1): Integer;
begin
Result := StartPos;
while (Result <= Length(Str)) and not (Str[Result] in CharSet) do
Inc(Result);
if Result > Length(Str) then
Result := 0;
end;
function Check(Line: string): Boolean;
var
Stack: TCharStack;
Pos: Integer;
begin
Result := False;
Stack := TCharStack.Create;
try
Pos := FindFirstOf(Line, FindSet);
while(Pos <> 0) do
begin
case Line[Pos] of
'(':
Stack.Push(Line[Pos]);
')':
if (Stack.Count = 0) or (Stack.top <> '(') then
begin
ShowMessage('右括号匹配不成功: ' + Copy(Line, 1, Pos));
Exit;
//Halt;
end
else
Stack.Pop();
end;
Pos := FindFirstOf(Line, FindSet, Pos +1);
end;
if Stack.Count > 0 then
ShowMessage('左括号匹配不成功!')
else
Result := True
finally
Stack.Free;
end;
end;
相关文档:
var
Form1: TForm1;
a, b, c: Integer;
implementation
{$R *.dfm}
procedure test1(x, y, z: integer);
asm
mov a,eax
mov b,edx
mov c,ecx
end;
procedure test2(x, y, z: integer);
var
i,j,k: integer;
asm
mov i,eax
mov j,edx
mov k,ecx
mov eax,[esp+8]
mov a,eax
mov ......
为了加快硬件的访问速度, 编译器通常要使用"数据对齐", 譬如:
//下面结构中: SizeOf(TRec) = 6; 因为 b 在这里也要占 2 字节.
TRec = record
a: Word;
b: Byte;
c: Word;
end
;
//下面结构中: SizeOf(TRec) = 16; 这里的 a 和 b 共占了 8 个字节.
TRec = record
a: Byte;
b: Byte;
c: Do ......
http://hi.baidu.com/rainbow_chaser/blog/item/7eb5f001c0d864e508fa93ac.html
1.防止刷新时闪烁的终极解决办法
{ 防止刷新时闪烁的终极解决办法(对付双缓冲无效时) }
Perform($000B, 0, 0); //锁屏幕 防止闪烁
// 做一些会发生严重闪烁的事情..
//解锁屏幕并重画
Perform($000B, 1, 0);
RedrawWindow(Handle, nil, ......
转自:http://www.52delphi.com/List.asp?ID=597&Page=1
核心提示:函数需要 uses Direct3D9,D3DX9; 偶然发现一个函数可以直接保存表面到文件1!所以修改了一下,函数为:...
procedure CaptureScreen(Const FileName: string);
var
BitsPerPixel: Byte;
pD3D: IDirect3D9;
pSurface: IDirect3DSurface9;
......
Delphi字符串函数大全
uses StrUtils;
【字符串函数大全】
首部 function AnsiResemblesText(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 返回两个字符串是否相似
  ......