括号匹配(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 ......
1.防止刷新时闪烁的终极解决办法
{ 防止刷新时闪烁的终极解决办法(对付双缓冲无效时) }
Perform($000B, 0, 0); //锁屏幕 防止闪烁
// 做一些会发生严重闪烁的事情..
//解锁屏幕并重画
Perform($000B, 1, 0);
RedrawWindow(Handle, nil, 0, RDW_FRAME + RDW_INVALIDATE + R ......
http://hi.baidu.com/rainbow_chaser/blog/item/7eb5f001c0d864e508fa93ac.html
1.防止刷新时闪烁的终极解决办法
{ 防止刷新时闪烁的终极解决办法(对付双缓冲无效时) }
Perform($000B, 0, 0); //锁屏幕 防止闪烁
// 做一些会发生严重闪烁的事情..
//解锁屏幕并重画
Perform($000B, 1, 0);
RedrawWindow(Handle, nil, ......
Delphi字符串函数大全
uses StrUtils;
【字符串函数大全】
首部 function AnsiResemblesText(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 返回两个字符串是否相似
  ......
TreeView由节点构成,建树通过对TreeView.items属性进行操作。Items是一个TTreeNodes对象,这是一个TTreeNode集。
一、针对TTreeNodes,也就是 TreeView.Items,有这些属性:
1、count,节点个数。
2、item[index] ,通过index得到节点。
二、针对TTreeNodes,也就是 TreeView.Items,常用的添加节点的操作 ......