2025年3月26日 星期三
「諸神黃昏」為何會爆發?誰該為這場北歐神幾乎全滅的悲劇負責?【神話故事集】#31|奇幻圖書館
2025年3月25日 星期二
曾是神最寵愛的光之天使首領,路西法為何背叛上帝,成為墮落天使?【奇幻百科全書】#19|奇幻圖書館
所謂的魔鬼與異端真的都是邪惡不堪的存在嗎,
其實很多時候,惡魔只是不被這社會的規則秩序所接受的一方而已吧,
畢竟當你手裡握有權力,要編故事與羅織罪名根本不是什麼困難的事情」
這種想法本身就是一種權威感,
只是差別在你有沒有辦法對質疑你的人做出制裁而已,
儘管我們小心翼翼,不想變成那個墮落天使,
諷刺的是,我們每個人都可能成為別人眼中的路西法,不是嗎」
2025年2月20日 星期四
Delphi 表單建立/釋放時的事件順序
在 Delphi 中,當一個表單 (Form) 被建立時,會依序觸發以下事件:
Constructor (Create):
在這個階段,表單的物件會被建立,但視窗還沒有初始化。
如果使用的是 TForm.Create(nil),此時還沒有分配 Parent,也沒有顯示。
CreateWnd:
建立表單的 Windows 視窗句柄 (Handle)。
此時可以進行與視窗句柄相關的操作,例如 API 呼叫。
Loaded:
當表單是從 DFM (表單文件) 加載時會觸發。
所有的組件屬性和子組件都已經被初始化。
適合在這裡進行一些屬性設定或初始化動作。
OnCreate (或 FormCreate 事件):
當表單完成建立時觸發。
通常用於初始化變數、設定控制項屬性或載入資料。
OnShow:
當表單即將顯示在螢幕上時觸發。
表單已經可見,但還沒有繪製完全。
適合用於需要在顯示時更新畫面的操作,例如 UI 資料刷新。
OnActivate:
當表單獲得焦點 (成為最上層視窗) 時觸發。
每次表單被切換回來時都會觸發,不只是第一次顯示時。
OnPaint:
當表單需要重繪時觸發。
一般用於自訂繪圖邏輯,例如畫布 (Canvas) 操作。
OnResize (可選,視情況而定):
當表單大小改變時觸發。
可用於調整內部控制項的佈局。
當表單關閉或釋放時,事件順序如下:
OnCloseQuery:
在關閉前詢問是否允許關閉 (CanClose 參數)。
可用於彈出確認視窗或檢查條件。
OnClose:
當表單正在關閉時觸發。
可透過 Action 參數決定是隱藏還是釋放表單。
OnHide:
當表單從螢幕上消失時觸發。
OnDestroy (或 FormDestroy 事件):
在表單物件被釋放前觸發。
通常用於釋放資源、清理記憶體或結束程序。
Destructor (Destroy):
最後的資源釋放動作,然後表單物件從記憶體中移除。
2024年12月25日 星期三
判斷環境處於開發狀態
使用 {$IFDEF DEBUG} 編譯條件
在開發過程中,您可以通過設置 DEBUG 編譯器條件來區分開發模式和執行模式。通常在 IDE 中執行程式時,會啟用 DEBUG 模式。delphi
複製程式碼
procedure CheckMode;
begin
{$IFDEF DEBUG}
ShowMessage('目前是開發模式');
{$ELSE}
ShowMessage('目前是執行模式');
{$ENDIF}
end;
注意:您需要在專案的編譯選項中啟用 DEBUG 定義。
判斷 IsDebuggerPresent(Windows 專用)
在 Windows 系統中,可以使用 Windows API 的 IsDebuggerPresent 函數來判斷程式是否被除錯工具附加,這可以間接反映是否處於開發模式。delphi
複製程式碼
uses
Winapi.Windows;
function IsDevelopmentMode: Boolean;
begin
Result := IsDebuggerPresent;
end;
procedure CheckMode;
begin
if IsDevelopmentMode then
ShowMessage('目前是開發模式')
else
ShowMessage('目前是執行模式');
end;
判斷設計時期元件的 ComponentState
如果您正在開發元件,您可以檢查元件的 ComponentState 是否包含 csDesigning 標誌來判斷是否處於設計時期:delphi
複製程式碼
function IsDesignTime(AComponent: TComponent): Boolean;
begin
Result := csDesigning in AComponent.ComponentState;
end;
// 使用範例
if IsDesignTime(Self) then
ShowMessage('目前是開發模式(設計時期)')
else
ShowMessage('目前是執行模式');
適用場景
檢查程式是否在 IDE 中執行:使用 IsDebuggerPresent 或 {$IFDEF DEBUG}。
檢查元件是否處於設計時期:使用 csDesigning。
請依據您的需求選擇合適的方式。如果需要更多協助,請提供您的具體需求!
2024年12月17日 星期二
老虎在古代為什麼叫大蟲
在古代,老虎被稱為「大蟲」有幾個原因。首先,這個稱呼與唐朝皇室有關。唐高祖李淵的祖父名叫李虎,為了避諱皇室的名字,李淵下令將老虎改稱為「大蟲」。
此外,「大」這個字在古代是一種對生物的尊稱,而「蟲」在古代漢語中有著廣泛的涵義,不僅指昆蟲,還可以指代大型猛獸。這樣的稱呼也出現在《水滸傳》中,例如武松打虎的故事中,老虎被稱為「大蟲」。
Copilot
2024年11月14日 星期四
Delphi 專案編譯前/後的觸發事件
Project → Options
如果需要將編譯後的文件複製到其他資料夾,可以參考上圖的作法
在 Post-build events → Commads 填入
XCopy "$(OUTPUTDIR)$(OUTPUTFILENAME)" "C:\Temp" /Y
2024年10月17日 星期四
ADO.Connection 開啟Excel Xlsx文件,「找不到提供者,它可能未被正確安裝」
2024年8月4日 星期日
2024年6月17日 星期一
瀏覽器頁面內容另存為圖檔
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleCtrls,
SHDocVw, MSHTML, ActiveX, Vcl.Imaging.jpeg;
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; const [Ref] URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
procedure SaveWebPageAsImage(WebBrowser: TWebBrowser; FileName: string; AFullPage:Boolean=True);
end;
Form1: TForm1;
var
HTMLDocument: IHTMLDocument2;
HTMLBody: IHTMLElement2;
ViewObject: IViewObject;
Bitmap: TBitmap;
JpegImage: TJpegImage;
vRect: TRect;
DC: HDC;
orgWidth, orgHeight:Integer;
orgAlign:TAlign;
begin
if not Assigned(WebBrowser.Document) then
Exit;
begin
Visible := False;
orgWidth := Width;
orgHeight := Height;
orgAlign := Align;
Align := alCustom;
end;
HTMLDocument := WebBrowser.Document as IHTMLDocument2;
HTMLBody := HTMLDocument.body as IHTMLElement2;
// Create a bitmap to hold the webpage content
Bitmap := TBitmap.Create;
try
// Get the view object of the document
if HTMLDocument.QueryInterface(IViewObject, ViewObject) = S_OK then
begin
// Get the bounding rectangle of the WebBrowser
if AFullPage then
begin
WebBrowser.Width := HTMLBody.scrollWidth;
WebBrowser.Height := HTMLBody.scrollHeight+30;
end;
vRect := Rect(0, 0, WebBrowser.Width, WebBrowser.Height);
Bitmap.Width := WebBrowser.Width;
Bitmap.Height := WebBrowser.Height;
// Get a device context (DC) for the bitmap canvas
DC := Bitmap.Canvas.Handle;
// Draw the content of the WebBrowser into the bitmap
ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, 0, DC, @vRect, nil, nil, 0);
end;
// Create a TJpegImage and assign the bitmap to it
JpegImage := TJpegImage.Create;
try
JpegImage.Assign(Bitmap);
JpegImage.SaveToFile(FileName);
finally
JpegImage.Free;
end;
finally
Bitmap.Free;
with WebBrowser do
begin
Width := orgWidth;
Height := orgHeight;
Align := orgAlign;
Visible := True;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; const [Ref] URL: OleVariant);
begin
SaveWebPageAsImage(TWebBrowser(ASender), 'c:\temp\test.jpg');
end;
begin
WebBrowser1.Silent := True;
Webbrowser1.Navigate('https://www.google.com.tw');
end;
end.
2024年6月13日 星期四
Delphi 在桌面產生捷徑
Windows, SysUtils, ComObj, ShlObj;
var
WSHShell: Variant;
Shortcut: Variant;
DesktopPath: array[0..MAX_PATH] of Char;
begin
// 初始化 WSHShell
WSHShell := CreateOleObject('WScript.Shell');
// 獲取桌面路徑
SHGetSpecialFolderPath(0, DesktopPath, CSIDL_DESKTOP, False);
// 創建捷徑對象
Shortcut := WSHShell.CreateShortcut(IncludeTrailingPathDelimiter(DesktopPath) + ShortcutName + '.lnk');
// 設置捷徑目標路徑和描述
Shortcut.TargetPath := TargetPath;
Shortcut.Description := 'Shortcut to ' + ShortcutName;
// 保存捷徑
Shortcut.Save;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// 創建 A.EXE 的捷徑到桌面
CreateShortcutOnDesktop('C:\path\to\A.EXE', 'A.EXE Shortcut');
end;
2024年5月15日 星期三
SQL 十進位轉分數
取最大公因數
Create FUNCTION dbo.GCD(@a INT, @b INT)RETURNS INT
AS
BEGIN
--最大公因數
WHILE @b != 0
BEGIN
DECLARE @temp INT;
SET @temp = @b;
SET @b = @a % @b;
SET @a = @temp;
END
RETURN @a;
END;
十進位轉分數
SQL 英呎轉分數
取最大公因數
AS
BEGIN
--最大公因數
WHILE @b != 0
BEGIN
DECLARE @temp INT;
SET @temp = @b;
SET @b = @a % @b;
SET @a = @temp;
END
RETURN @a;
END;
英吋轉分數
2024年5月14日 星期二
DBGrid FixedCols Selution
DBGrid FixedCols Selution
function SelectCell(ACol, ARow: Longint): Boolean; Override;
...
...
function TFixDBGrid.SelectCell(ACol, ARow: Longint): Boolean;
Begin
Result := Inherited SelectCell(ACol, ARow);
If ACol < FixedCols Then
Result := False;
End;
...
參考轉: https://delfusa.main.jp/delfusafloor/archive/www.nifty.ne.jp_forum_fdelphi/samples/00715.html
2024年5月6日 星期一
蟾宮折桂
蟾宮折桂
蟾宮,指月亮。折桂,比喻科舉及第。參見「折桂」條。蟾宮折桂相傳月中有桂樹,用以比喻科舉登第。元.施惠《幽閨記》第一一齣:「胸中書富五車,筆下句高千古,鎮朝經暮史,寐晚興夙,擬蟾宮折桂雲梯步。」《孽海花》第五回:「舉人是月宮裡管的,祇要吳剛老爹修桂樹的玉斧砍下一枝半枝,肯賜給我們爺,我們爺就可以中舉,名叫蟾宮折桂。」
https://dict.idioms.moe.edu.tw/idiomView.jsp?ID=11566&webMd=2&la=0









