|
Delphi/Pascal言語のソースコード整形例 |
|
|
|
|
|
SourceFormatX は優れた構文解析エンジンを元に作られています。ですのであらゆるスタイルで書かれたソースコードを美しく整形することができます。以下の例のようなめちゃくちゃなコードでさえも、整形することが可能です。
|
これは極端な例ですが。SourceFormatXに搭載されている強力な Delphi / Object Pascal 言語のパーサーエンジンの実力を感じて頂けるかと思います。
unit AutoScale;interface uses Windows,Controls,Forms,Classes,Dialogs;type
TAutoScale=class(TComponent)privateMatrix:Variant;PW,PH,BCount:Integer;procedure
GetFormInfo(Form:TForm);public constructor Create(AOwner:TComponent);override;
procedure Init(Form:TForm);procedure Resize(Form:TForm);published end;var
AutoScale1:TAutoScale;procedure Register;implementation
procedure Register;begin RegisterComponents('Uwis',[TAutoScale]);end;
constructor TAutoScale.Create(AOwner:TComponent);begin inherited; if(AOwner is TForm)then Init(AOwner as TForm)else
ShowMessage('The owner of TAutoScale is NOT a TForm.');end;
procedure TAutoScale.Init(Form:TForm);begin BCount:=Form.ControlCount-1;
Matrix:=VarArrayCreate([0,BCount,0,3], VarInteger);GetFormInfo(Form);end;
procedure TAutoScale.GetFormInfo(Form:TForm); var I:Integer;RGN:TRect;begin
for I:=0 to BCount do begin RGN:=Form.Controls[I].BoundsRect;Matrix[I,0]:=RGN.
Left;Matrix[I,1]:=RGN.Top;Matrix[I,2]:=RGN.Right;Matrix[I,3]:=RGN.Bottom;end;PW
:=Form.ClientWidth;PH:=Form.ClientHeight;end;procedure TAutoScale.Resize(Form:
TForm);var L,T,LL,TT,RR,BB,W,H,WW,HH,I:Integer;Fas:Boolean;begin WW:=Form.
ClientWidth;HH:=Form.ClientHeight;Fas:=Form.AutoScroll;Form.AutoScroll:=False;
for I:=0 to(Form.ControlCount-1)do begin LL:=((Matrix[I,0]*WW)div PW);TT:=((
Matrix[I,1]*HH)div PH);RR:=((Matrix[I,2]*WW)div PW);BB:=((Matrix[I,3]*HH)div PH)
;L:=LL;T:=TT;W:=RR-LL;H:=BB-TT;SetBounds(Form.Controls[I]);end;end;end.
unit AutoScale;
interface
uses Windows, Controls, Forms, Classes, Dialogs;
type
TAutoScale = class(TComponent)
privateMatrix: Variant;
PW, PH, BCount: Integer;
procedure GetFormInfo(Form: TForm);
public
constructor Create(AOwner: TComponent); override;
procedure Init(Form: TForm);
procedure Resize(Form: TForm);
published
end;
var
AutoScale1: TAutoScale;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Uwis', [TAutoScale]);
end;
constructor TAutoScale.Create(AOwner: TComponent);
begin
inherited; if (AOwner is TForm) then
Init(AOwner as TForm)
else
ShowMessage('The owner of TAutoScale is NOT a TForm.');
end;
procedure TAutoScale.Init(Form: TForm);
begin
BCount := Form.ControlCount - 1;
Matrix := VarArrayCreate([0, BCount, 0, 3], VarInteger);
GetFormInfo(Form);
end;
procedure TAutoScale.GetFormInfo(Form: TForm);
var
I: Integer;
RGN: TRect;
begin
for I := 0 to BCount do
begin
RGN := Form.Controls[I].BoundsRect;
Matrix[I, 0] := RGN.Left;
Matrix[I, 1] := RGN.Top;
Matrix[I, 2] := RGN.Right;
Matrix[I, 3] := RGN.Bottom;
end;
PW := Form.ClientWidth;
PH := Form.ClientHeight;
end;
procedure TAutoScale.Resize(Form: TForm);
var
L, T, LL, TT, RR, BB, W, H, WW, HH, I: Integer;
Fas: Boolean;
begin
WW := Form.ClientWidth;
HH := Form.ClientHeight;
Fas := Form.AutoScroll;
Form.AutoScroll := false;
for I := 0 to (Form.ControlCount - 1) do
begin
LL := ((Matrix[I, 0] * WW) div PW);
TT := ((Matrix[I, 1] * HH) div PH);
RR := ((Matrix[I, 2] * WW) div PW);
BB := ((Matrix[I, 3] * HH) div PH);
L := LL;
T := TT;
W := RR - LL;
H := BB - TT;
SetBounds(Form.Controls[I]);
end;
end;
end.
再び手動でDelphi/Pascal言語のソースコードを整形するために時を浪費しないで下さい! SourceFormatX体験版の無料ダウンロード!
|