首先在Additional->新增一個ApplicationEvents,然後在事件OnShortCut新增下列程式碼:
procedure TFmain.ApplicationEvents1ShortCut(var Msg: TWMKey;
var Handled: Boolean);
begin
if (TWMKey(Msg).CharCode = VK_ESCAPE) then
self.close
end;
function GetContext(const AIniFilename: string): string;
var
FIniFile: TIniFile;
Context_Main, Context_Function: string;
begin
if not FileExists(AIniFilename) then exit;
FIniFile:= TIniFile.Create(AIniFilename);
try
Context_Main:= FIniFile.ReadString('Context', 'Main', '');
Context_Function:= FIniFile.ReadString('Context', 'Function', '');
Result:= format('%s%s', [Context_Main, Context_Function]);
finally
FIniFile.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Filename: string;
begin
Filename:= 'Context.ini';
Edit1.Text:= GetContext(Filename);
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,IniFiles,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
AIniFileName = 'funds.ini';
implementation
{$R *.dfm}
//讀取資訊
procedure TForm1.Button1Click(Sender: TObject);
var
FIniFile: TIniFile;
begin
//if not FileExists(AIniFilename) then exit;
FIniFile:= TIniFile.Create(AIniFilename);
try
memo1.Lines.add(FIniFile.ReadString('基金顯示資訊','國內或國外基金', ''));
memo1.Lines.add(FIniFile.ReadString('基金顯示資訊','基金公司', ''));
memo1.Lines.add(FIniFile.ReadString('基金顯示資訊','基金名稱', ''));
memo1.Lines.add(FIniFile.ReadString('基金顯示資訊','指標數目', ''));
finally
FIniFile.Free;
end;
end;
//寫入ini
procedure TForm1.Button2Click(Sender: TObject);
var
FIniFile: TIniFile;
begin
//if not FileExists(AIniFilename) then exit;
FIniFile:= TIniFile.Create(AIniFilename);
try
FIniFile.WriteString('基金顯示資訊','指標數目', '0');
FIniFile.WriteString('指標1','指標名稱', 'MACD');
FIniFile.WriteString('指標1','參數1', '5');
FIniFile.WriteString('指標1','參數2', '3');
FIniFile.WriteString('指標1','參數3', '3');
FIniFile.WriteString('指標1','參數4', '3');
finally
FIniFile.Free;
end;
end;
//刪除
procedure TForm1.Button3Click(Sender: TObject);
var
FIniFile: TIniFile;
begin
FIniFile:= TIniFile.Create(AIniFilename);
try
FIniFile.EraseSection('基金顯示資訊');
FIniFile.DeleteKey('指標1','指標名稱');
finally
FIniFile.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
FIniFile: TIniFile;
begin
if not FileExists(AIniFilename) then //可以放在temp目錄內好了
begin
FIniFile:= TIniFile.Create(AiniFileName);
try
FIniFile.WriteString('基金顯示資訊','國內或國外基金', '國內基金');
FIniFile.WriteString('基金顯示資訊','基金公司', '富達證券');
FIniFile.WriteString('基金顯示資訊','基金名稱', '富達新興市場基金');
FIniFile.WriteString('基金顯示資訊','指標數目', '0');
FIniFile.WriteString('指標1','指標名稱', '');
FIniFile.WriteString('指標1','參數1', '');
FIniFile.WriteString('指標1','參數2', '');
FIniFile.WriteString('指標1','參數3', '');
FIniFile.WriteString('指標1','參數4', '');
FIniFile.WriteString('指標2','指標名稱', '');
FIniFile.WriteString('指標2','參數1', '');
FIniFile.WriteString('指標2','參數2', '');
FIniFile.WriteString('指標2','參數3', '');
FIniFile.WriteString('指標2','參數4', '');
FIniFile.WriteString('指標3','指標名稱', '');
FIniFile.WriteString('指標3','參數1', '');
FIniFile.WriteString('指標3','參數2', '');
FIniFile.WriteString('指標3','參數3', '');
FIniFile.WriteString('指標3','參數4', '');
finally
FIniFile.Free;
end;
end;
end;
end.
uses
ShellAPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
// 「執行 notepad」
ShellExecute(Handle, nil, 'notepad', nil, nil, SW_SHOWNORMAL);
// 「打開 word 檔」
ShellExecute(Handle, 'oppen', 'C:\a.doc', nil, nil, SW_SHOWNORMAL);
// 「列印 excel 檔」
ShellExecute(Handle, 'print', 'C:\a.xls', nil, nil, SW_SHOWNORMAL);
// 「開網頁」
ShellExecute(Handle, nil, 'http://www.borland.com/', nil, nil, SW_SHOWNORMAL);
// 「寄信」
ShellExecute(Handle, nil, 'mailto:name@host.com?subject=主旨&body=內文', nil, nil, SW_SHOWNORMAL);
// 「我的電腦」
ShellExecute(0, 'open', '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}', nil, nil, SW_NORMAL);
// 「網路上的芳鄰」
ShellExecute(0, 'open', '::{208D2C60-3AEA-1069-A2D7-08002B30309D}', nil, nil, SW_NORMAL);
// 「我的文件」
ShellExecute(0, 'open', '::{450D8FBA-AD25-11D0-98A8-0800361B1103}', nil, nil, SW_NORMAL);
// 「控制台」
ShellExecute(0, 'open', '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}', nil, nil, SW_NORMAL);
// 「印表機」
ShellExecute(0, 'open', '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D}', nil, nil, SW_NORMAL);
end;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
md5;
function LogEntry(Cmd, Msg: string; Dig: MD5Digest): string;
begin
Result := Format('%s(''%s'') =' + #13#10 + ' %s', [Cmd, Msg, MD5Print(Dig)]); //以後要拿來用就MD5Print(Edit1.Text)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.add(LogEntry('MD5String', Edit1.Text, MD5String(Edit1.Text)));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit2.Text := OPenDialog1.FileName;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
Memo1.Lines.add(LogEntry('MD5File', Edit2.Text, MD5File(Edit2.Text)));
Screen.Cursor := crDefault;
end;
end.
unit md5;
// ------------------------------------------------------------------
interface
// ------------------------------------------------------------------
uses
Windows;
type
MD5Count = array[0..1] of DWORD;
MD5State = array[0..3] of DWORD;
MD5Block = array[0..15] of DWORD;
MD5CBits = array[0..7] of byte;
MD5Digest = array[0..15] of byte;
MD5Buffer = array[0..63] of byte;
MD5Context = record
State: MD5State;
Count: MD5Count;
Buffer: MD5Buffer;
end;
procedure MD5Init(var Context: MD5Context);
procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
function MD5String(M: string): MD5Digest;
function MD5File(N: string): MD5Digest;
function MD5Print(D: MD5Digest): string;
function MD5Match(D1, D2: MD5Digest): boolean;
// ------------------------------------------------------------------
IMPLEMENTATION
// ------------------------------------------------------------------
var
PADDING: MD5Buffer = (
$80, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00,
$00, $00, $00, $00, $00, $00, $00, $00
);
function F(x, y, z: DWORD): DWORD;
begin
Result := (x and y) or ((not x) and z);
end;
function G(x, y, z: DWORD): DWORD;
begin
Result := (x and z) or (y and (not z));
end;
function H(x, y, z: DWORD): DWORD;
begin
Result := x xor y xor z;
end;
function I(x, y, z: DWORD): DWORD;
begin
Result := y xor (x or (not z));
end;
procedure rot(var x: DWORD; n: BYTE);
begin
x := (x shl n) or (x shr (32 - n));
end;
procedure FF(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, F(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure GG(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, G(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure HH(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, H(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
procedure II(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);
begin
inc(a, I(b, c, d) + x + ac);
rot(a, s);
inc(a, b);
end;
// ------------------------------------------------------------------
// Encode Count bytes at Source into (Count / 4) DWORDs at Target
procedure Encode(Source, Target: pointer; Count: longword);
var
S: PByte;
T: PDWORD;
I: longword;
begin
S := Source;
T := Target;
for I := 1 to Count div 4 do begin
T^ := S^;
inc(S);
T^ := T^ or (S^ shl 8);
inc(S);
T^ := T^ or (S^ shl 16);
inc(S);
T^ := T^ or (S^ shl 24);
inc(S);
inc(T);
end;
end;
// Decode Count DWORDs at Source into (Count * 4) Bytes at Target
procedure Decode(Source, Target: pointer; Count: longword);
var
S: PDWORD;
T: PByte;
I: longword;
begin
S := Source;
T := Target;
for I := 1 to Count do begin
T^ := S^ and $ff;
inc(T);
T^ := (S^ shr 8) and $ff;
inc(T);
T^ := (S^ shr 16) and $ff;
inc(T);
T^ := (S^ shr 24) and $ff;
inc(T);
inc(S);
end;
end;
// Transform State according to first 64 bytes at Buffer
procedure Transform(Buffer: pointer; var State: MD5State);
var
a, b, c, d: DWORD;
Block: MD5Block;
begin
Encode(Buffer, @Block, 64);
a := State[0];
b := State[1];
c := State[2];
d := State[3];
FF (a, b, c, d, Block[ 0], 7, $d76aa478);
FF (d, a, b, c, Block[ 1], 12, $e8c7b756);
FF (c, d, a, b, Block[ 2], 17, $242070db);
FF (b, c, d, a, Block[ 3], 22, $c1bdceee);
FF (a, b, c, d, Block[ 4], 7, $f57c0faf);
FF (d, a, b, c, Block[ 5], 12, $4787c62a);
FF (c, d, a, b, Block[ 6], 17, $a8304613);
FF (b, c, d, a, Block[ 7], 22, $fd469501);
FF (a, b, c, d, Block[ 8], 7, $698098d8);
FF (d, a, b, c, Block[ 9], 12, $8b44f7af);
FF (c, d, a, b, Block[10], 17, $ffff5bb1);
FF (b, c, d, a, Block[11], 22, $895cd7be);
FF (a, b, c, d, Block[12], 7, $6b901122);
FF (d, a, b, c, Block[13], 12, $fd987193);
FF (c, d, a, b, Block[14], 17, $a679438e);
FF (b, c, d, a, Block[15], 22, $49b40821);
GG (a, b, c, d, Block[ 1], 5, $f61e2562);
GG (d, a, b, c, Block[ 6], 9, $c040b340);
GG (c, d, a, b, Block[11], 14, $265e5a51);
GG (b, c, d, a, Block[ 0], 20, $e9b6c7aa);
GG (a, b, c, d, Block[ 5], 5, $d62f105d);
GG (d, a, b, c, Block[10], 9, $2441453);
GG (c, d, a, b, Block[15], 14, $d8a1e681);
GG (b, c, d, a, Block[ 4], 20, $e7d3fbc8);
GG (a, b, c, d, Block[ 9], 5, $21e1cde6);
GG (d, a, b, c, Block[14], 9, $c33707d6);
GG (c, d, a, b, Block[ 3], 14, $f4d50d87);
GG (b, c, d, a, Block[ 8], 20, $455a14ed);
GG (a, b, c, d, Block[13], 5, $a9e3e905);
GG (d, a, b, c, Block[ 2], 9, $fcefa3f8);
GG (c, d, a, b, Block[ 7], 14, $676f02d9);
GG (b, c, d, a, Block[12], 20, $8d2a4c8a);
HH (a, b, c, d, Block[ 5], 4, $fffa3942);
HH (d, a, b, c, Block[ 8], 11, $8771f681);
HH (c, d, a, b, Block[11], 16, $6d9d6122);
HH (b, c, d, a, Block[14], 23, $fde5380c);
HH (a, b, c, d, Block[ 1], 4, $a4beea44);
HH (d, a, b, c, Block[ 4], 11, $4bdecfa9);
HH (c, d, a, b, Block[ 7], 16, $f6bb4b60);
HH (b, c, d, a, Block[10], 23, $bebfbc70);
HH (a, b, c, d, Block[13], 4, $289b7ec6);
HH (d, a, b, c, Block[ 0], 11, $eaa127fa);
HH (c, d, a, b, Block[ 3], 16, $d4ef3085);
HH (b, c, d, a, Block[ 6], 23, $4881d05);
HH (a, b, c, d, Block[ 9], 4, $d9d4d039);
HH (d, a, b, c, Block[12], 11, $e6db99e5);
HH (c, d, a, b, Block[15], 16, $1fa27cf8);
HH (b, c, d, a, Block[ 2], 23, $c4ac5665);
II (a, b, c, d, Block[ 0], 6, $f4292244);
II (d, a, b, c, Block[ 7], 10, $432aff97);
II (c, d, a, b, Block[14], 15, $ab9423a7);
II (b, c, d, a, Block[ 5], 21, $fc93a039);
II (a, b, c, d, Block[12], 6, $655b59c3);
II (d, a, b, c, Block[ 3], 10, $8f0ccc92);
II (c, d, a, b, Block[10], 15, $ffeff47d);
II (b, c, d, a, Block[ 1], 21, $85845dd1);
II (a, b, c, d, Block[ 8], 6, $6fa87e4f);
II (d, a, b, c, Block[15], 10, $fe2ce6e0);
II (c, d, a, b, Block[ 6], 15, $a3014314);
II (b, c, d, a, Block[13], 21, $4e0811a1);
II (a, b, c, d, Block[ 4], 6, $f7537e82);
II (d, a, b, c, Block[11], 10, $bd3af235);
II (c, d, a, b, Block[ 2], 15, $2ad7d2bb);
II (b, c, d, a, Block[ 9], 21, $eb86d391);
inc(State[0], a);
inc(State[1], b);
inc(State[2], c);
inc(State[3], d);
end;
// ------------------------------------------------------------------
// Initialize given Context
procedure MD5Init(var Context: MD5Context);
begin
with Context do begin
State[0] := $67452301;
State[1] := $efcdab89;
State[2] := $98badcfe;
State[3] := $10325476;
Count[0] := 0;
Count[1] := 0;
ZeroMemory(@Buffer, SizeOf(MD5Buffer));
end;
end;
// Update given Context to include Length bytes of Input
procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
var
Index: longword;
PartLen: longword;
I: longword;
begin
with Context do begin
Index := (Count[0] shr 3) and $3f;
inc(Count[0], Length shl 3);
if Count[0] < (Length shl 3) then inc(Count[1]);
inc(Count[1], Length shr 29);
end;
PartLen := 64 - Index;
if Length >= PartLen then begin
CopyMemory(@Context.Buffer[Index], Input, PartLen);
Transform(@Context.Buffer, Context.State);
I := PartLen;
while I + 63 < Length do begin
Transform(@Input[I], Context.State);
inc(I, 64);
end;
Index := 0;
end else I := 0;
CopyMemory(@Context.Buffer[Index], @Input[I], Length - I);
end;
// Finalize given Context, create Digest and zeroize Context
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
var
Bits: MD5CBits;
Index: longword;
PadLen: longword;
begin
Decode(@Context.Count, @Bits, 2);
Index := (Context.Count[0] shr 3) and $3f;
if Index < 56 then PadLen := 56 - Index else PadLen := 120 - Index;
MD5Update(Context, @PADDING, PadLen);
MD5Update(Context, @Bits, 8);
Decode(@Context.State, @Digest, 4);
ZeroMemory(@Context, SizeOf(MD5Context));
end;
// ------------------------------------------------------------------
// Create digest of given Message
function MD5String(M: string): MD5Digest;
var
Context: MD5Context;
begin
MD5Init(Context);
MD5Update(Context, pChar(M), length(M));
MD5Final(Context, Result);
end;
// Create digest of file with given Name
function MD5File(N: string): MD5Digest;
var
FileHandle: THandle;
MapHandle: THandle;
ViewPointer: pointer;
Context: MD5Context;
begin
MD5Init(Context);
FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
if FileHandle <> INVALID_HANDLE_VALUE then try
MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);
if MapHandle <> 0 then try
ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);
if ViewPointer <> nil then try
MD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));
finally
UnmapViewOfFile(ViewPointer);
end;
finally
CloseHandle(MapHandle);
end;
finally
CloseHandle(FileHandle);
end;
MD5Final(Context, Result);
end;
// Create hex representation of given Digest
function MD5Print(D: MD5Digest): string;
var
I: byte;
const
Digits: array[0..15] of char =
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
begin
Result := '';
for I := 0 to 15 do Result := Result + Digits[(D[I] shr 4) and $0f] + Digits[D[I] and $0f];
end;
// -----------------------------------------------------------------------------------------------
// Compare two Digests
function MD5Match(D1, D2: MD5Digest): boolean;
var
I: byte;
begin
I := 0;
Result := TRUE;
while Result and (I < 16) do begin
Result := D1[I] = D2[I];
inc(I);
end;
end;
end.
unit getinfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, sockets, Registry;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function MacAddress: string;
implementation
{$R *.dfm}
function MacAddress: string;
var
Lib: Cardinal;
Func: function(GUID: PGUID): Longint; stdcall;
GUID1, GUID2: TGUID;
begin
Result := '';
Lib := LoadLibrary('rpcrt4.dll');
if Lib <> 0 then
begin
if Win32Platform <>VER_PLATFORM_WIN32_NT then
@Func := GetProcAddress(Lib, 'UuidCreate')
else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
if Assigned(Func) then
begin
if (Func(@GUID1) = 0) and
(Func(@GUID2) = 0) and
(GUID1.D4[2] = GUID2.D4[2]) and
(GUID1.D4[3] = GUID2.D4[3]) and
(GUID1.D4[4] = GUID2.D4[4]) and
(GUID1.D4[5] = GUID2.D4[5]) and
(GUID1.D4[6] = GUID2.D4[6]) and
(GUID1.D4[7] = GUID2.D4[7]) then
begin
Result :=
IntToHex(GUID1.D4[2], 2) + '-' +
IntToHex(GUID1.D4[3], 2) + '-' +
IntToHex(GUID1.D4[4], 2) + '-' +
IntToHex(GUID1.D4[5], 2) + '-' +
IntToHex(GUID1.D4[6], 2) + '-' +
IntToHex(GUID1.D4[7], 2);
end;
end;
FreeLibrary(Lib);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
sock : TIpSocket;
GlobalMemoryInfo:TMemoryStatus;
rg:tregistry;
skey:string;
begin
sock := TIpSocket.Create(self);
Edit1.text:=sock.localHostName;
rg:=tregistry.create;
rg.RootKey:=HKEY_LOCAL_MACHINE;
skey:='HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0';
if rg.KeyExists(skey) then
begin
rg.openkey(skey,true);
Edit2.text:=trim(rg.ReadString('ProcessorNameString'));
rg.closekey;
end;
rg.free;
GlobalMemoryStatus(GlobalMemoryInfo);
Edit3.Text:=Format('%.0n',[GlobalMemoryInfo.dwTotalPhys/1024]);
Edit4.text:=MacAddress;
end;
end.
program Project2;
uses
Windows;
var
n: integer;
begin
for n:=1 to 32767 do
Windows.Beep(n,30);
end.
AnimateWindow(handle,500,AW_Center);
AnimateWindow(handle,500,AW_BLEND or AW_ACTIVATE);
AnimateWindow(handle,500,AW_Center or AW_Hide or AW_BLEND);
unit ULang;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, inifiles, TypInfo,UOsLang;
function InitStringFile():boolean;//初始化字串檔(解檔及取得檔名)
procedure LoadStringFile();//經由初始化過後,再讀取字串檔。
procedure SaveWording(var frm:TForm; sWordingFile:string);
procedure ReadWording(var frm:TForm; sWordingFile:string);
procedure InitGlobalVariable;
function GetWorkDirectory:String;
function GetTmpDirectory(): string ;
var
g_cLang :char;
g_saMsg :array[1..3600] of String; // 訊息字串表
g_sStrFile :string; // 字串檔名
g_sTempPath :string; // (WorkingPath)
g_sWorkPath :string; // (WorkingPath)
implementation
procedure InitGlobalVariable;
begin
g_sWorkPath:=GetWorkDirectory();
g_sTempPath:=GetTmpDirectory();
end;
//初始化字串檔(解檔及取得檔名) by v
function InitStringFile():boolean;
var
sStringFileName:string;
begin
//result:=false;
g_cLang := GetLanguage;// 取得系統語系
if not (g_cLang in ['0','1','2','3']) then
g_cLang := '2' ;// 目前只提供四種語言,內訂英文
sStringFileName:='wording' + g_cLang + '.txt' ;
g_sStrFile:=g_sWorkPath +sStringFileName;
//showmessage(g_sStrFile);
{
//檢查目前執行環境同目錄下,若無字串檔,則解檔案至 temp 路徑下
if not FileExists(g_sStrFile) then
begin
g_sStrFile:=g_sTempPath+sStringFileName;
if( StrIComp(PChar(ExtractDLL(g_sTempPath, sStringFileName, false)),PChar(g_sStrFile)) <> 0 ) then // 解壓縮文字檔
begin
ErrMsgBox('Extract wording file failed !');
exit;
end ;
end;
}
result:=true;
end;
//讀取訊息字串
procedure LoadStringFile();
var
ini:TIniFile;
i:integer;
//sReportLanguageFile:String;
begin
ini := TIniFile.Create(g_sStrFile);
try
for i:=Low(g_saMsg) to High(g_saMsg) do
g_saMsg[i] := ini.ReadString('Message', IntToStr(i), '');
finally
ini.Free;
end;
end;
{=============================================================================
=}
{ 函式敘
述: }
{ 儲存控制項字串
表 }
{=============================================================================
=}
procedure SaveWording(var frm:TForm; sWordingFile:string);
var
i: Integer;
ini: TIniFile;
proInfo: PPropInfo;
sStr: String;
begin
with frm do
begin
ini := TIniFile.Create(sWordingFile);
try
ini.WriteString(Name, Name, Caption);
for i:=0 to ComponentCount-1 do
begin
// caption
proInfo := GetPropInfo(Components[i].ClassInfo, 'Caption');
if (proInfo <> nil) then
begin
sStr := GetStrProp(Components[i], proInfo);
if( Length(sStr) <> 0 ) then
ini.WriteString(Name, Components[i].Name, sStr);
end;
end;
finally
ini.Free;
end;
end;
end;
{=============================================================================
=}
{ 函式敘
述: }
{ 讀取控制項字串表並設定控制項字
串 }
{=============================================================================
=}
procedure ReadWording(var frm:TForm; sWordingFile:string);
var
i: Integer;
ini: TIniFile;
proInfo: PPropInfo;
sStr: String;
FontObject: TFont;
begin
with frm do
begin
frm.PixelsPerInch := 96 ;
frm.Scaled := false ;
ini := TIniFile.Create(sWordingFile);
try
//讀入元件字串
Caption := ini.ReadString(Name, Name, '');
Font.Name:=Screen.MenuFont.Name; //940304 by v 新增
Font.Charset:=Screen.MenuFont.Charset;//940304 by v 新增
Font.Size:=10;
for i:=0 to ComponentCount-1 do
begin
proInfo := GetPropInfo(Components[i].ClassInfo, 'Caption');
if (proInfo <> nil) then
begin
sStr := ini.ReadString(Name, Components[i].Name, GetStrProp
(Components[i], proInfo));
SetStrProp(Components[i], proInfo, sStr);
end;
// 設定字型
proInfo := GetPropInfo(Components[i].ClassInfo, 'Font');
if (proInfo <> nil) then
begin
FontObject := TFont(GetObjectProp(Components[i], proInfo, TFont));
FontObject.Name := Screen.MenuFont.Name;
FontObject.Charset := Screen.MenuFont.Charset;
FontObject.Size := 10;
//為了解決eltree上半部頭會被截掉1pixel的問題 因此更改為12
//FontObject.Size := 10;
//FontObject.
//FontObject.Height := 14;
//FontObject.Size := 8;//20050909 by v 芝瓏說要改8 (效果很差)
end;
end;
finally
ini.Free;
end;
end;
end;
function GetWorkDirectory;
var
aBuf: array[0..260] of Char;
begin
GetModuleFileName(HINSTANCE, @aBuf[0], SizeOf(aBuf));
Result := IncludeTrailingBackslash(ExtractFilePath(StrPas(aBuf)));
end;
function GetTmpDirectory(): string ;
var
dwBuffSize : DWORD ;
cBuffer : array[0..MAX_PATH] of char ;
begin
dwBuffSize := MAX_PATH ;
GetTempPath( dwBuffSize, cBuffer) ;
Result := cBuffer ;
end;
end.
unit UOsLang;
interface
uses
Windows, IniFiles, SysUtils, Registry;
function CreateLogFile:Boolean;
function GetLanguage:Char;
function GetSystemDefaultFontName(FixedFont: Boolean=false): String;
implementation
(*-------------------------------------------------------------------------
取得OS主語系
*)
function PRIMARYLANGID(lgid: WORD): WORD;
begin
Result:=lgid and $03FF;
end;
(*-------------------------------------------------------------------------
取得OS副語系
*)
function SUBLANGID(lgid: WORD): WORD;
begin
Result:=lgid shr 10;
end;
(*-------------------------------------------------------------------------
傳回語系代碼
*)
function GetLanguage(): char;
var
wLangID: LANGID;
wPrimaryLangID, wSubLangID: WORD;
begin
//取得OS預設語系
wLangID:=GetSystemDefaultLangID();
wPrimaryLangID:=PRIMARYLANGID(wLangID);
wSubLangID:=SUBLANGID(wLangID);
case wPrimaryLangID of
//中文...
LANG_CHINESE:
begin
case wSubLangID of
SUBLANG_CHINESE_TRADITIONAL, //繁體
SUBLANG_CHINESE_HONGKONG: //香港也是用繁體
begin
Result:='0';
end;//break
SUBLANG_CHINESE_SIMPLIFIED: //簡體
begin
Result:='1';
end;//break
else
Result:='0'; //預設為繁體中文
end;//case end
end;
//英文...
LANG_ENGLISH:
begin
Result:='2';
end;
//日文...
LANG_JAPANESE:
begin
Result:='3';
end;
//韓文...
LANG_KOREAN:
begin
Result:='4';
end;
//泰文...
LANG_THAI:
begin
Result:='5';
end;
//法文...
LANG_FRENCH:
begin
Result:='9';
end;
//德文...
LANG_GERMAN:
begin
Result:='A';
end;
//義大利文...
LANG_ITALIAN:
begin
Result:='B';
end;
//西班牙文...
LANG_SPANISH:
begin
Result:='C';
end;
//葡萄牙文...
LANG_PORTUGUESE:
begin
Result:='D';
end;
//俄文...
LANG_RUSSIAN:
begin
Result:='F';
end;
//荷蘭文...
LANG_DUTCH:
begin
Result:='I';
end;
//預設語系是英文...
else //defualt
Result:='2';
end;
end;
{===========================================================================}
{ 函式敘述: }
{ 取得系統預設的字型名稱 }
{ 例如:繁體中文Windows => 新細明體 }
{===========================================================================}
function GetSystemDefaultFontName(FixedFont: Boolean=false): String;
const
OEM_CodePage = 'MIME\Database\Codepage\';
ProportionalFont = 'ProportionalFont';
FixWidthFont = 'FixedWidthFont';
var
reg: TRegistry;
CodePage: String;
begin
Result := 'System';
CodePage := IntToStr(GetOEMCP);
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CLASSES_ROOT;
if reg.OpenKeyReadOnly(OEM_CodePage) then
begin
if reg.KeyExists(CodePage) and reg.OpenKeyReadOnly(CodePage) then
begin
if FixedFont then
Result := reg.ReadString(FixWidthFont)
else
if reg.ValueExists(ProportionalFont) then
Result := reg.ReadString(ProportionalFont)
else if reg.ValueExists(FixWidthFont) then
Result := reg.ReadString(FixWidthFont);
end;
end;
finally
reg.CloseKey;
reg.Free;
end;
end;
function CreateLogFile:Boolean;
const
_sLangFile='Language.ini';
var
ini: TIniFile;
begin
Result:=true;
ini:=TIniFile.Create(_sLangFile);
try
try
ini.WriteString('vars','language',GetLanguage);
except
Result:=false;
end;
finally
ini.Free;
end;
end;
end.
uses ULang
SaveWording(TForm(self), g_sStrFile);
InitGlobalVariable; //加到主要Form即可
InitStringFile; //加到主要Form即可
LoadStringFile; //加到主要Form即可
ReadWording(TForm(self), g_sStrFile); //每個Form都要加
g_saMsg[1] //其中數字1在[Message]的1的字串
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FMTBcd, StdCtrls, DB, ADODB, SqlExpr, Grids, DBGrids;
type
TForm1 = class(TForm)
ADOStoredProc1: TADOStoredProc;
ADOConnection1: TADOConnection;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOStoredProc1.ProcedureName:='q1';
ADOStoredProc1.parameters.clear;
ADOStoredProc1.parameters.CreateParameter('va', ftInteger, pdInput, 1, edit1.text);
ADOStoredProc1.Prepared;
ADOStoredProc1.execproc;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, Gauges;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Label1: TLabel;
Button5: TButton;
Gauge1: TGauge;
procedure FormActivate(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure WebBrowser1ProgressChange(ASender: TObject; Progress,
ProgressMax: Integer);
procedure WebBrowser1CommandStateChange(ASender: TObject; Command: Integer;
Enable: WordBool);
procedure WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//上一頁
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.GoBack;
end;
//下一頁
procedure TForm1.Button2Click(Sender: TObject);
begin
WebBrowser1.GoForward ;
end;
//停止
procedure TForm1.Button3Click(Sender: TObject);
begin
WebBrowser1.Stop;
end;
//更新
procedure TForm1.Button4Click(Sender: TObject);
begin
WebBrowser1.Refresh ;
end;
//進入網站
procedure TForm1.Button5Click(Sender: TObject);
begin
WebBrowser1.Navigate(Edit1.Text);
end;
//當鍵盤按Enter
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then Button5.Click ;
end;
//當視窗活動時,設定焦點,記得focus都要在Activate才能設喔!
procedure TForm1.FormActivate(Sender: TObject);
begin
Edit1.SetFocus ;
end;
//網頁連結成功,網址列顯示URL
procedure TForm1.WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Edit1.Text:=URL;
end;
//處理進度情況設定
procedure TForm1.WebBrowser1ProgressChange(ASender: TObject; Progress,
ProgressMax: Integer);
begin
Gauge1.MaxValue :=ProgressMax;
Gauge1.Progress:=progress;
end;
//上一頁及下一頁按紐判斷可否被按
procedure TForm1.WebBrowser1CommandStateChange(ASender: TObject;
Command: Integer; Enable: WordBool);
begin
if (Command = CSC_NAVIGATEFORWARD) then
Button3.Enabled := Enable
else if (Command = CSC_NAVIGATEBACK) then
Button2.Enabled := Enable
end;
end.
unit readhtmleasy;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, OleCtrls, SHDocVw, mshtml, Grids, ComCtrls, StrUtils,activex;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
slTemp: TStringList;
HTMLDoc: IHTMLDocument2;
begin
Cursor := crHourGlass;
webbrowser1.Navigate('http://www.stockq.org');
HTMLDoc := webbrowser1.Document as IHTMLDocument2;
while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do
Application.ProcessMessages;
Cursor := crDefault;
HTMLDoc := webbrowser1.Document as IHTMLDocument2;
slTemp := TStringList.Create;
slTemp.text := HTMLDoc.body.innertext;
memo1.text := slTemp.text;
end;
end.
no e
uses ADODB, ComObj;
var
function SQLOpenOK(ADO:TADOQuery; sSQL:string): boolean;
function SQLExecuteOK(ADO:TADOQuery; sSQL:string): boolean;
{-------------------------------------------}
//執行SQL命令,成功=true ,失敗=false
function SQLOpenOK(ADO:TADOQuery; sSQL:string): boolean;
function QuotedMsg(sMsg:string): string;
begin
sMsg:=Trim(sMsg);
if sMsg='' then Result:=''
else Result:=' ['+sMsg+']';
end;
begin
Result:=False;
try
ADO.Close;
ADO.SQL.Clear;
ADO.SQL.Add(sSQL);
ADO.Open;
except
On E:EOleException Do
begin
ShowMessage(E.Message);
if E.ErrorCode=E_FAIL then //連線失敗
begin
ShowMessage('與DB連線失敗');
Application.Terminate;
end;
exit;
end;
end;
Result:=True;
end;
{-------------------------------------------}
function SQLExecuteOK(ADO:TADOQuery; sSQL:string): boolean;
function QuotedMsg(sMsg:string): string;
begin
sMsg:=Trim(sMsg);
if sMsg='' then Result:=''
else Result:=' ['+sMsg+']';
end;
begin
Result:=False;
try
ADO.Close;
ADO.SQL.Clear;
ADO.SQL.Add(sSQL);
ADO.ExecSQL;
except
On E:EOleException Do
begin
ShowMessage(E.Message);
if E.ErrorCode=E_FAIL then //連線失敗
begin
ShowMessage('與DB連線失敗');
Application.Terminate;
end;
exit;
end;
end;
Result:=True;
end;
try
ADOConnection1.Connected := True;
except
Showmessage('連線失敗!');
end;
if not SQLOpenOK(ADOQuery1,'SELECT * FROM 資料表名') then
ShowMessage('Query ERROR!!');
s := 'create table 富達新興 (';
s := s + '流水號 AUTOINCREMENT NOT NULL';
s := s + ', [日期] Date';
s := s + ', 淨值 int';
s := s + ', PRIMARY KEY (流水號)';
s := s + ');';
if not SQLExecuteOK(ADOQuery1,s) then
ShowMessage('Query ERROR!!');
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses CommonUni;
{$R *.dfm}
end.