Skip to content

TValueListEditorDemo 项目分析

项目信息

文件结构

TValueListEditorDemo/
├── 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.ValueListEditor1 = ValueListEditor(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button1.OnClick = self.Button1Click

        # 创建 TValueListEditor 组件
        self.valueListEditor = ValueListEditor(self)
        self.valueListEditor.Parent = self  # 设置父组件为当前表单
        self.valueListEditor.Left = 10
        self.valueListEditor.Top = 50

        # 添加列名到 TValueListEditor
        self.valueListEditor.Strings.Add('Key1=Value1')  # 添加键值对
        self.valueListEditor.Strings.Add('Key2=Value2')  # 添加另一个键值对

    def Button1Click(self, Sender):
        ShowMessage(self.valueListEditor.Strings.Text)  # 显示所有键值对
        for i in range(1, self.ValueListEditor1.RowCount):  # 从1开始遍历每一行
              # 显示每行键值对的值
            ShowMessage(self.ValueListEditor1.Values[self.ValueListEditor1.Keys[i]])

设计文件: Unit1.sct

def Button1Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 402
  ClientWidth = 656
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object ValueListEditor1: TValueListEditor
    Left = 336
    Top = 40
    Width = 306
    Height = 300
    Strings.Strings = (
      #21016#22791'='#35947#24030#29287
      #20851#32701'='#27721#23551#20141#20399
      #24352#39134'='#20116#34382#19978#23558)
    TabOrder = 0
    TitleCaptions.Strings = (
      #22995#21517
      #32844#20301)
  end
  object Button1: TButton
    Left = 336
    Top = 344
    Width = 306
    Height = 25
    Caption = 'Show Value'
    TabOrder = 1
    OnClick = Button1Click
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • ValueListEditor1 (TValueListEditor)
  • Button1 (TButton)

技术特点

  • 包含3个GUI组件
  • 定义1个事件处理

窗体属性

  • caption: Show Value
  • height: 402
  • width: 656

代码分析

导入的模块: - import os - from glcl import *

定义的类: - Form1

定义的方法: - init - Button1Click

事件绑定: - self.Button1.OnClick = self.Button1Click