var Str: string[]; StrLen: Byte absolute Str; begin Str := ; Edit1.Text := IntToStr(StrLen); end;
type TDemo = class private protected procedure X; virtual; abstract; public constructor Create; destructor Destroy; override; published end;
if (a>) and (b>) then var a,b,c: Integer; begin c := (a and b); end; if a> and b> then if a>( and b)> then if (a>) and (b>) then
var Arr1: array [..] of Integer; var Arr2: array of Integer; function X(A: array of Integer): Integer; var i: Integer; begin Result := ; for i := to Length(A)- do Result := Result + A[i]; end;
procedure BtnClick(Sender:TObject); begin (Sender as TButton).Caption := ; end; (HTTPRIO as IExp).GetConnection; var i: Integer; s: string; begin s := (i as string); end; s := string(i);
function IntToHex(Value: Integer; Digits: Integer): string; asm CMP EDX, JBE @A1 xor EDX, EDX @A1: PUSH ESI MOV ESI, ESP SUB ESP, PUSH ECX MOV ECX, CALL CvtInt MOV EDX, ESI POP EAX CALL System.@LStrFromPCharLen ADD ESP, POP ESI end;
function IntToHex(AValue: Int64): string; assembler;
type TDemo = class automated Str:WideString; end; type TDemo = class automated Str: AnsiString; end
procedure X; begin ShowMessage(); end; for i:= to do begin sum := sum + i; if sum > then Break; end;
function GetDays(AYear,AMonth: Integer): Integer; begin case AMonth of ,,,,,,: Result := ; ,,,: Result := ; : begin if IsLeapYear(AYear) then Result:= else Result:=; end; else Result:=; end;
int X(int i) { return i*2; }
function X(i: Integer): Integer; Cdecl; external ;
type ClassDemo = class(TObject) private public constructor Create; end; type ClassA = class private public procedure Y; end; type ClassB = class(ClassA) private public class procedure X; end; procedure ClassA.Y; begin Self.X; end;
const MyFileName = ; const MyInteger = ; function X(const i: Integer): string;
type ClassDemo = class(TObject) private fValue: Integer; public constructor Create; end; constructor ClassDemo.Create; begin fValue := ; end;
package DATAX; requires rtl, clx; contains Db, DBLocal, DBXpress; end.
type ClassDemo = class private fValue: Integer; published property Value: Integer read fValue write fValue default ; end; property strings[Index: Integer]: string read GetString write PutString; Default;
type ClassDemo = class(TComponent) public destructor Destroy;override; end; destructor Destroy; overload;
type IStringsDisp = dispinterface [] property ControlDefault[Index: Integer]: Olevariant dispid ; default; function Count: Integer; dispid ; property Item[Index: Integer]: Olevariant dispid ; procedure Remove(Index: Integer); dispid ; procedure Clear; dispid ; function Add(Item: Olevariant): Integer; dispid ; function _NewEnum: IUnknown; dispid -; end;
var a,b,c:Integer; begin a := ; b := ; c := a div b; end;
for i := to do sum:=sum+i; while i < do begin sum := sum + i; Inc(i); end; try i := StrToInt(s); except on exception do ShowMessage(); end; with Memo1.Lines do begin Clear; Append(); Append(); end;
for i := downto do ListBox1.Items.Add(IntToStr(i));
procedure X(i: Integer); dynamic;
if a > b then c := a else c:=b; case Tag Of :Result:=; :Result:=; :Result:=; else Result:=; end; try i := StrToInt(s); Excpet on EZeroDivide do Result := ; on EOverflow do Result := ; else Result := ; end;
procedure X; begin with Button1 do begin if Button1.ShowHint then Button1.Caption := else Button1.Caption := ; end; end; package DATAX; requires rtl, clx; contains Db, DBLocal, DBXpress; end.
try i := StrToInt(s); except ShowMessage(); end;
function Add(a,b: Integer): Integer; export; function Add(a,b: Integer): Integer; stdcall; external ;
library Demo; function X(i: Integer): string; stdcall; begin Result:=IntToStr(i); end; exports X; begin end. library Demo; function X(i: Integer): string; overload; stdcall; begin Result := IntToStr(i); end; function X(s: string): Integer; overload; stdcall; begin Result := StrToInt(s); end; exports X(i: Integer) name , X(s: string) name ; begin end.
procedure X(i:Integer);external; function A(FileName: string): string; external ; function A(Name: string): string; overload; stdcall; external name ; function A(Code: Integer): string; overload; stdcall; external name ;
function Add(a,b: Integer): Integer; Far; function Add(a,b: Integer): Integer; stdcall; external ;
type TPerson = record PName: string[]; PAge: Integer; end; var PFile: file of TPerson;
initialization ActiveX.OleInitialize(nil); finalization ActiveX.OleUninitialize;
try Node := Node.GetNext; Edit1.Text := Node.Text; finally Node := nil; end;
for i := to do sum := sum + i; for i := downto do Inc(sum);
function X(i: Integer): Integer; forward; procedure Y(s: string); forward; ... function X; begin Result := i * ; end; procedure Y; begin WriteLn(s); end;
function X(i: Integer): Integer; type TFun = function(i: Integer): Integer of object;
var a,b: Integer; label X,Y; begin if a > b then goto X else goto Y; X: WriteLn(); Y: WriteLn(); end;
var a,b: Integer; begin a := ; b := ; if a>b then WriteLn( + IntToStr(a)) else WriteLn( + IntToStr(b)); end; if a > b then begin WriteLn(); WriteLn( + IntToStr(a)); WriteLn( + IntToStr(b)); End else WriteLn();
implementation uses frmAbout; begin FormAbout.Show; end;
type IMyInterface = interface procedure P1; procedure P2; end; TMyImplclass = class procedure P1; procedure P2; end; TMyclass = class(TInterfacedObject, IMyInterface) FMyImplClass: TMyImplClass; property MyImplClass: TMyImplclass read FMyImplclass implements IMyInterface; procedure IMyInterface.P1 = MyP1; procedure MyP1; end; procedure IMyInterface.P1 = MyP1;
type TCol = (cA,cB,cC); TCols = set of TCol; var Cols: TCols; begin Cols := [cA,cB]; if cA in Cols then ShowMessage() else ShowMessage(); end; Uses Unit1 in ; var s: string; sl: TStringList; begin ... for s In sl do begin ShowMessage(s); end; end;
type TForm1 = class(TForm) private function GetInfo(const Index: Integer): Longint; procedure SetInfo(const Index: Integer; const Value: Longint); public property iLeft:Longint index read GetInfo write SetInfo; property iTop:Longint index read GetInfo write SetInfo; property iWidth:Longint index read GetInfo write SetInfo; property iHeight:Longint index read GetInfo write SetInfo; end; function TForm1.GetInfo(const Index: Integer): Longint; begin case Index of : result := self.Left; : Result := self.Top; : result := self.Width; : result := self.Height; end; end; property Selected[Index: Integer]: Boolean read GetSelected write SetSelected;
type TDemo = class(TComponent) public constructor Create(AOwner: TComponent); override; end; constructor TDemo.Create(AOwner: TComponent); begin inherited Create(AOwner); end; inherited Create(AOwner); Inherited;
function IntToStr(Value: Integer): string; asm InLine; PUSH ESI MOV ESI, ESP SUB ESP, xor ECX, ECX PUSH EDX xor EDX, EDX CALL CvtInt MOV EDX, ESI POP EAX CALL System.@LStrFromPCharLen ADD ESP, POP ESI end;
Interface uses frmAbout; var FAbout: TFormAbout; begin FAbout := TFormAbout.Create(Self); FAbout.Show; end; type IMalloc = interface(IInterface) [] function Alloc(Size: Integer): Pointer; stdcall; function Realloc(P: Pointer; Size: Integer): Pointer; stdcall; procedure Free(P: Pointer); stdcall; function GetSize(P: Pointer): Integer; stdcall; function DidAlloc(P: Pointer): Integer; stdcall; procedure HeapMinimize; stdcall; end;
var Comp: TComponent; begin ... if Comp Is TEdit then (Comp as TEdit).Text := ; end;
library Editors; uses EdInit, EdInOut, EdFormat, EdPrint; exports InitEditors, doneEditors name done, InsertText name Insert, DeleteSelection name Delete, FormatSelection, PrintSelection name Print, SetErrorHandler; begin InitLibrary; end.
procedure Refresh(var Msg: TMessageRecordtype); message ID_REFRESH; procedure Refresh(var Msg: TMessageRecordtype); begin if Chr(Msg.Code) = then ... else inherited; end;
var a,b,c: Integer; begin a := ; b := ; c := a mod b; end;
function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; stdcall; external name ;
function Add(a,b: Integer): Integer; near; function Add(a,b: Integer): Integer; stdcall; external ;
while Node <> nil do begin ListBox1.Items.Add(Node.Text); Node := Node.GetNext; end;
type TClassA = class private fValue: Integer; published property Value: Integer read fValue write fValue default ; end; TClassB = class(TClassA) published property Value:Integer read fValue write fValue nodefault; end;
if a > b then if not(a < b) then procedure Button1Click(Sender: TObject); begin StatusBar1.Visible := not StatusBar1.Visible; end;
type ODemoA = object end; ODemoB = object(ODemoA) end; type TMyFun = function(i: Integer): Integer of Object; TMyProc = procedure(s: string) of object;
case Tag Of : Result := ; : Result := ; end; type TDemo = class of TComponent; var MyInt: array of Integer; var MyFile: file of Byte; type TCol = (cA,cB,cC); TCols = set of TCol; type MyFun = function(I: Integer): Integer of Object;
try i := StrToInt(s); except on E: exception do ShowMessage(E.Message); end;
if (a>) or (b>) then var a,b,c: Integer; begin c := (a or b); end; 例如: if a> or b> then if a>( or b)> then if (a>) or (b>) then
procedure X(out i: Integer; out s: string); begin i := i * ; s := s + ; end; procedure TForm1.Button1Click(Sender: TObject); var i: Integer; s: string; begin i := ; s := ; X(i,s); end;
function X(i: Integer): string; overload; function X(s: string): string; overload; type TDemo = class(TComponent) public procedure CreateWnd(AOwner: TWinControl); overload; end; procedure CreateWnd; procedure CreateWnd(AOwner: TWinControl);
procedure Create(AOwner: TComponent); override; type TClassA = class procedure X; virtual; end; TClassB = class(TClassA) procedure X; override; end; procedure X; procedure X;
package DATAX; requires rtl, clx; contains MyUnit in ; end.
type TPerson = packed Record PName: string[]; PAge: Integer; end; MyArray: packed array of PChar;
function X(i: Integer): Integer; Pascal; begin Result := i * ; end;
procedure X(i: Integer); type TProc = procedure(i: Integer) of object;
program Project1; uses Forms, Unit1 in ; begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.
type TDemo = class Private fValue: Integr; Published property Value: Integer read fValue write fValue; end; type TOnTextChange=procedure (Sender: TObject) of object; TDemo = class private fEvent: TOnTexChange; published property OntextChange: TOnTextChange read fEvent write fEvent; end;
function GetString(i: Integer): string; begin if i < then raise exception.Create(); Result := IntToStr(i); end; try i := StrToInt(s); except on E: exception do raise exception.Create(E.Message); end;
private fValue: Integer; published property Value: Integer read fValue;
property ReadOnly;
type TPerson = record PName: string[]; PAge: Integer; end;
function Add(a,b: Integer): Integer; Register; Register procedure Register; begin RegisterComponents(, [TDemo]); end;
type TClassA = class procedure X; end; TClassB = class(TClassA) procedure X; reintroduce; end; TClassC = class(TClassB) procedure X(i: Integer); reintroduce; end;
i := ; repeat sum := sum + i; Inc(i); until(i >= );
package DATAX; requires rtl, clx; end.
ResourceString CreateError = ; OpenError = ; LineTooLong = ; ProductName = ; SomeResourceString = SomeTrueConstant;
procedure X(s: WideString); safecall; procedure X(s: PAnsiString);
type TCol = (cA,cB,cC); TCols = set of TCol; var Cols: Tcols; begin Cols := Cols + [cA,cB]; end;
var x: Integer; begin X := shl ; end;
var x: Integer; begin X := shr ; end;
Library Demo; function X(i: Integer): Integer; stdcall; begin Result := i * ; end; exports X; begin end. function X(i: Integer): Integer; stdcall; external ;
property Value: string read fValue write fValue stored True;
var Str: string;
var a,b: Integer; begin if a > b then WriteLn() else WriteLn(); end;
threadvar S: AnsiString; S := ; S := ;
for i := to do ListBox1.Items.Add(IntToStr(i));
type TDemo = class end; type TCol = (cA,cB,cC); TInt = Integer;
Unit Unit1; Interface uses Classes; implementation end.
Interface uses Classes; Implemention uses frmAbout;
var i: Integer; s: string; function X(var i: Integer): Integer;
function printf(Format: PChar): Integer; cdecl; varargs;
procedure X(i: Integer); virtual;
i := ; while i < do begin sum := sum + i; Inc(i); end;
with Form1.Memo1.Lines do begin Clear; Append(); Append(); SaveToFile(); end; Form1.Memo1.Lines.Clear; Form1.Memo1.Lines.Append(); Form1.Memo1.Lines.Append(); Form1.Memo1.Lines.SaveToFile();
private fValue: Integer; published property Value: Integer write fValue;
property writeonly;
var a,b: Integer; begin a := ; b := ; if a xor b then WriteLn() else WriteLn(); end; WriteLn(IntToStr( xor ));
轉自萬一老師:http://www.cnblogs.com/del/archive/2008/06/23/1228562.html
一、前言: Delphi默認支持OpenGl,可以uses
Delphi統計字數。許多讀者朋友都使用過Windows
樹網的核(codevs 1167)題解,codevs1167
本例效果圖:代碼文件:unit Unit1;i
本例效果圖:unit Unit1; interface
ActiveX技術雖然是一項古老的技術,但是卻有著廣泛的