TFindDialogDemo 项目分析¶
项目信息¶
- 项目名称: TFindDialogDemo
- 下载链接: TFindDialogDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TFindDialogDemo/
├── Extractor_Icon.ico
├── Project1.py
├── Project1.xml
├── Unit1.py
├── Unit1.pydfm
├── Unit1.sct
├── Unit1.sfm
主程序文件: Project1.py¶
from glcl import *
from Unit1 import *
def main():
Application.Initialize()
Application.Title = 'Project1'
Application.MainFormOnTaskbar = True
Application.Icon.LoadFromFile(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Extractor_Icon.ico"))
MainForm = Form1(Application)
MainForm.Show()
FreeConsole()
Application.Run()
MainForm.Free()
if __name__ == '__main__':
main()
单元文件: Unit1.py¶
import os
from glcl import *
class Form1(Form):
def __init__(self, owner):
self.Button1 = Button(self)
self.FindDialog1 = FindDialog(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button1.OnClick = self.Button1Click
# 创建一个按钮用于打开查找对话框
self.find_button = Button(self)
self.find_button.Parent = self # 设置父控件为窗体
self.find_button.Caption = "Find" # 设置标题
self.find_button.Left = 150 # 设置按钮左边位置
self.find_button.Top = 100 # 设置按钮顶边位置
self.find_button.OnClick = self.show_find_dialog # 绑定点击事件
def show_find_dialog(self, Sender):
# 创建查找对话框实例
find_dialog = FindDialog(self)
# 设置要查找的文本
find_dialog.FindText = 'aaa'
# 显示查找对话框并检查用户是否按下“确定”
if find_dialog.Execute():
search_text = find_dialog.FindText # 获取用户输入的查找内容
ShowMessage(f"Searching for: {search_text}") # 显示查找内容
# 这里可以添加实际的查找逻辑,例如在文本框中查找内容
def Button1Click(self, Sender):
if self.FindDialog1.Execute():
ShowMessage(self.FindDialog1.FindText)
设计文件: Unit1.sct¶
def Button1Click(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 121
ClientWidth = 454
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object Button1: TButton
Left = 358
Top = 80
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object FindDialog1: TFindDialog
FindText = 'aaa'
Options = [frDown, frMatchCase]
Left = 304
Top = 80
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
对话框组件演示
使用的组件¶
- Form1 (TForm)
- Button1 (TButton)
- FindDialog1 (TFindDialog)
技术特点¶
- 包含3个GUI组件
- 定义2个事件处理
窗体属性¶
- caption: Button1
- height: 121
- width: 454
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - show_find_dialog - Button1Click
事件绑定: - self.Button1.OnClick = self.Button1Click - self.find_button.OnClick = self.show_find_dialog # 绑定点击事件