gpt4 book ai didi

delphi - 加载动态 .ini 标识符

转载 作者:行者123 更新时间:2023-12-03 15:37:41 27 4
gpt4 key购买 nike

我正在创建我的学生计划表的虚拟版本,它基本上可以让你记下你有哪些科目的作业。

这是界面: enter image description here

用户从组合框中选择主题,并在相邻的备忘录中输入一些注释。完成后,他们将单击“保存”按钮,将其保存到 .ini 文件中。所选日期将成为部分名称,主题将成为标识符,备忘录中的文本将成为每个标识符的值。

注意:有 7 个可能的主题。

我的问题是在选择日期时加载组合框和备忘录,因为每个日期的标识符总是不同的。

例如:

2月16日用户输入(界面):

英语 - 阅读小说的第 127 页。
数学 - 完成第 6 章。

2 月 16 日,它在 .ini 文件中将如下所示:

[16/02/12]
English=Read up to page 127 of novel.
Maths=Complete chapter 6.

2月20日用户输入(界面):

SOSE - 阅读教科书。
法律研究 - 填写在线调查。

2 月 20 日,.ini 文件中的内容将如下所示:

[20/02/12]
SOSE=Read textbook.
Legal Studies=Fill in online survey.

现在您会看到,如果用户选择 2 月 16 日查看他们的任务,则无法加载,因为每个标识符都不同。

是否有更好的 .ini 文件替代方案?我怎样才能实现这一目标?

最佳答案

您可以使用TIniFile.ReadSections 获取各个日期,并使用TIniFile.ReadSection 获取该部分中的各个项目。这是一个简单的示例:

// Sample ini file

[16/02/12]
English=Read up to page 127 of novel.
Maths=Complete chapter 6.

[20/02/12]
SOSE=Read textbook.
Legal Studies=Fill in online survey.

代码:

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IniFiles;

type
TForm2 = class(TForm)
ListBox1: TListBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
FIni: TMemIniFile;
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

const
IniName = 'd:\Temp\SampleNotes.ini';

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FIni.Free;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
FIni := TMemIniFile.Create(IniName);
Memo1.Lines.Clear;
FIni.ReadSections(ListBox1.Items);
end;

procedure TForm2.ListBox1Click(Sender: TObject);
var
Section: string;
begin
if ListBox1.ItemIndex > -1 then
begin
Section := ListBox1.Items[ListBox1.ItemIndex];
FIni.ReadSection(Section, Memo1.Lines);
end;
end;

end.

上面的结果是:

Sample output image Sample output image 2

关于delphi - 加载动态 .ini 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9338283/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com