简体   繁体   English

Delphi Firemonkey TGrid的用法

[英]Delphi Firemonkey TGrid usage

I'm attempting to use a TGrid in the Delphi Firemonkey GUI library and I'm falling pretty badly on my face here. 我试图在Delphi Firemonkey GUI库中使用TGrid,但是我在这里的表情非常糟糕。

At this point in time, I have a TGrid in my form which three cells, a string cell, and 2 checkbox cells. 此时,我的表单中有一个TGrid,其中包含三个单元格,一个字符串单元格和2个复选框单元格。

At current execution, the Grid show up, with the three separate columns. 在当前执行时,将显示网格,其中包含三个单独的列。 However, nothing gets saved to the string cell and the checkbox cells do not appear unless you double click the cell. 但是,没有任何内容保存到字符串单元格,除非您双击该单元格,否则不会出现复选框单元格。 When you click away from the checkbox cell, the checkbox disappears. 当您单击远离复选框单元格时,该复选框消失。

I figure that I'm missing some crucial step here. 我认为这里缺少一些关键步骤。 I found a function for the TGrid class, OnGetValue and OnSetValue . 我找到了TGrid类的函数OnGetValueOnSetValue I figure these must have something to do with my problem, but the issue is I have absolutely no idea how to use them. 我认为这些必须与我的问题有关,但问题是我完全不知道如何使用它们。

Each calls for a (Sender: TObject; const ACol: Integer; const ARow: Integer; const Value: TValue) 每个调用一个(Sender: TObject; const ACol: Integer; const ARow: Integer; const Value: TValue)

I'm making an assumption with the sender, like when creating events for other controls, you're passing in self as the parameter of Sender. 我正在与发送方进行假设,例如在为其他控件创建事件时,您将self作为Sender的参数传递。 ACol and ARow are pretty obvious. ACol和ARow非常明显。 But I'm lost with the TValue parameter, as I can't seem to figure out what the heck TValue is. 但是我迷上了TValue参数,因为我似乎无法弄清楚到底什么是TValue。 Embarcadero provides this documentation for TValue, but it doesn't tell me a lot that is useful. Embarcadero为TValue提供了此文档 ,但是并没有告诉我很多有用的东西。

At this point, I'm just trying to simply get a cell to show its value and not lose its value when you click away. 在这一点上,我只是想简单地获得一个单元格以显示其值,而不是在您单击鼠标时失去其值。 I know I must be missing something, but I just don't know where to look. 我知道我一定会丢失一些东西,但我只是不知道在哪里看。 It feels like all the questions on this website and others relating to TGrid for Delphi are grossly outdated (I've seen them stretching all the way back to 2003). 感觉到该网站上的所有问题以及与TGrid for Delphi有关的其他问题都已经过时了(我看到它们一直延伸到2003年)。

I eventually found this this guide . 我最终找到了本指南

Long story short, the data is NOT held within the TGrid (which seems awful backwards to me, but I can now understand why). 长话短说,数据没有保存在TGrid中(这对我来说似乎很糟糕,但我现在可以理解为什么)。

In order to get data to show up, you need two events for the TGrid object itself (not the columns): 为了显示数据,TGrid对象本身(而不是列)需要两个事件:

OnGetValue and OnSetValue OnGetValue和OnSetValue

OnGetValue requests the data from the data structure, therefore it takes a row and column to locate the data within your structure. OnGetValue从数据结构中请求数据,因此需要一行和一列才能在结构中定位数据。 It puts this into the GUI for you. 它将它放入您的GUI中。

OnSetValue does the opposite, it supplies to your structure data from the GUI with a row and column. OnSetValue的作用与此相反,它通过GUI的行和列为您提供结构数据。

Hope this can help someone in the future, it took me a while to find out what Embarcadero didn't bother telling you, or pointing you at least somewhere to look. 希望这能对将来的人有所帮助,我花了一段时间才找出Embarcadero没告诉您的内容,或至少指向您要寻找的地方。

Define these two methods similarly as to how is explained in the guide. 与指南中的解释类似,定义这两种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM