// Replacevar reg: TPerlRegEx;begin reg := TPerlRegEx.Create(nil); reg.RegEx := 'ab'; reg.Replacement := '◆'; reg.Subject := 'ababab'; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: ◆◆◆ reg.Subject := 'ababab'; //下面四行程式, 相當於
本例:代碼檔案:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) CheckBox1: TCheckBox; procedure FormCreate(Sender: TObject); procedure
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5:
之前已經有了兩種多線程的同步方法:CriticalSection(臨界區) 和 Mutex(互斥), 這兩種同步方法差不多, 只是範圍不同;CriticalSection(臨界區) 類似於只有一個蹲位的公用廁所, 只能一個個地進; Mutex(互斥) 對象類似於接力賽中的接力棒, 某一時刻只能一個人持有, 誰拿著誰跑.什麼是 Semaphore(訊號或叫訊號量)呢?譬如到銀行辦業務、或者到車站買票, 原來只有一個服務員, 不管有多少人排隊等候, 業務只能一個個地來.假如增加了業務視窗,
GDI+ 有五種畫刷:實心畫刷: IGPSolidBrush陰影畫刷: IGPHatchBrush紋理畫刷: IGPTextureBrush線性漸層畫刷: IGPLinearGradientBrush路徑漸層畫刷: IGPPathGradientBrush它們分別有對應的實作類別:TGPSolidBrushTGPHatchBrushTGPTextureBrushTGPLinearGradientBrushTGPPathGradientBrush.五個畫刷都繼承自 IGPBrush, 但
發送try s := 'Hello world!'; stream := TStringStream.Create(s); IdTCPClient1.OpenWriteBuffer; IdTCPClient1.WriteInteger(stream.Size);//注意這裡:要先寫入流的長度,在讀取的時候如果使用 AThread.Connection.ReadStream(stream); IdTCPClient1.WriteStream(stream,
1、控制POS機的客戶顯示屏procedure TFrmMain.ShowMoney(Money_Port: String;Money_String:String);//Moneey_Port 顧顯介面Com1 or Com2 Money_String 顧顯顯示的內容var PrnFileName:TextFile;begin Assignfile(PrnFileName,Money_Port);
"臨界區"(CriticalSection): 當把一段代碼放入一個臨界區, 線程執行到臨界區時就獨佔了, 讓其他也要執行此代碼的線程先等等; 這和前面用的 Lock 和 UnLock 差不多; 使用格式如下:var CS: TRTLCriticalSection; {聲明一個 TRTLCriticalSection 結構類型變數; 它應該是全域的}InitializeCriticalSection(CS); {初始化}EnterCriticalSection(CS); {開始:
//替換一般字串var reg: TPerlRegEx;begin reg := TPerlRegEx.Create(nil); reg.Subject := '我愛DELPHI, 但Delphi不愛我!'; reg.RegEx := 'Delphi'; reg.Replacement := '◆'; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: 我愛DELPHI, 但◆不愛我!
TStream 是一個抽象的基類, 不能直接產生對象. 在具體的應用中, 主要使用它的子孫類:TFileStream: 檔案流TStringStream: 字串流TMemoryStream: 記憶體流TResourceStream: 資源檔流THandleStream: 是 TFileStream 的父類、TStream 的子類TCustomMemoryStream: 是 TMemoryStream 和 TResourceStream 的父類、TStream 的子類與流相關的常用類還有:
//從左右兩端提取指定數目的字串: AnsiLeftStr、AnsiRightStrvar ss,s: AnsiString;begin ss := 'abcdefg'; s := AnsiLeftStr(ss, 2); ShowMessage(s); {ab} s := AnsiRightStr(ss, 2); ShowMessage(s); {fg}end;//從指定位置開始提取指定長度的字串: AnsiMidStrvar ss,s: AnsiString;begin ss
//StrPas: 轉換 PChar 為 string; 現在可以直接賦值, 很少用了.var p: PChar; s: string;begin p := 'Delphi'; s := StrPas(p); ShowMessage(s); {Delphi}end;//StrNew、StrDispose: 建立與銷毀 PChar.var p: PChar;begin p := StrNew('Delphi'); ShowMessage(p); {Delphi}
通過路徑的 Warp 方法可以讓路徑在一個範圍內(四個點決定的範圍)變換;第一個參數可以是 3 個點或 4 個點的數組, 如果是 3 個的數組, 那麼第 4 個點將自動跟隨一個平行四邊形;第二個參數用來指定點數組的個數, 本例就是通過這個參數控制了點的個數;第三個參數是一個矩形, 這個矩形應該是路徑的外接矩形, 之後的參數都是可選的;第四個參數也是一個矩陣變換, 因由專門的 例子 , 這裡沒有嘗試;第五個參數是 TWarpMode(WarpModePerspective,
本例:代碼檔案:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls;type TForm1 = class(TForm) ListView1: TListView; Button1: TButton; Button2: TButton; CheckBox1:
Intersect {交集}Union {聯合}Xor_ {減去交集}Exclude {減去}Complement {不相交}//GDI+ 的地區能和矩形、路徑、另一個地區三種對象進行運算.本例:代碼檔案:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
DelphiX 提供了高效能的計時器 TDXTimer, 使用方法和 Timer 基本一樣.我們在使用 Timer 時, 很少把 Interval 設為 50 以下(這應該是它精確度的極限);使用 TDXTimer 可以把 Interval 置為 0, 表示儘可能地快!本例:代碼檔案:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
本例:代碼檔案:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DIB, StdCtrls;type TForm1 = class(TForm) DXPaintBox1: TDXPaintBox; Button1: TButton; Button2: TButton; procedure
//最常用的 stringvar str: string; {定義}begin str := '萬一'; {賦值} ShowMessage(IntToStr(Length(str))); {長度是: 4}end;//長字串 AnsiString; 在目前的版本(2007)中的預設狀態下, String 就是 AnsiStringvar str: AnsiString;begin str := '萬一'; ShowMessage(IntToStr(Length(str)));
IGPPrivateFontCollection.AddFontFile: 從檔案載入字型;IGPPrivateFontCollection.AddMemoryFont: 從記憶體載入字型AddFontFile 測試:uses GdiPlus;function GetFontsDirectory: string;var Len: Integer; buf: array[0..MAX_PATH-1] of Char;begin GetWindowsDirectory(buf, Length(
IGPImage 類提供的 Create 方法:Image := TGPImage.Create(檔案(或流), Boolean);//其中的布爾值預設 False; 如果為 True 則使用檔案(或流)中的已嵌入顏色管理資訊來進行顏色校正.{ 樣本1: 從檔案建立 }var Graphics: IGPGraphics; Image: IGPImage;begin Image := TGPImage.Create('C:\GdiPlusImg\Grapes.jpg');