XE StringGrid应用(G1属性触发G2)
unit UnitMain; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Rtti,
FMX.StdCtrls, FMX.Grid, FMX.Layouts, FMX.Controls.Presentation, FMX.Edit; type
TForm8 = class(TForm)
Edit1: TEdit;
G1: TStringGrid;
G2: TStringGrid;
StringColumn1: TStringColumn;
StringColumn2: TStringColumn;
Button1: TButton;
Button2: TButton;
procedure FormActivate(Sender: TObject);
procedure G1SelectCell(Sender: TObject; const ACol, ARow: Integer;
var CanSelect: Boolean);
procedure G2SelectCell(Sender: TObject; const ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
FRow2: Integer;
FRow1: Integer;
{ Private declarations }
procedure ShowG1(); // 显示表1
procedure ShowG2(); // 显示表2数据
procedure Item(); // 显示Edit等数据
procedure Save(); // 保存数据
procedure SetRow1(const Value: Integer);
procedure SetRow2(const Value: Integer);
public
{ Public declarations }
property Row1 : Integer read FRow1 write SetRow1; // 表1属性,OnSelectCell属性触发,改变时do something
property Row2 : Integer read FRow2 write SetRow2; // 表1属性,OnSelectCell属性触发,改变时do something
end; var
Form8: TForm8; implementation {$R *.fmx} procedure TForm8.Button1Click(Sender: TObject);
begin
G2.RowCount:=G2.RowCount+1; // 动态改变G2的Row
G2.Cells[0,G2.RowCount-1]:='aa';
end; procedure TForm8.Button2Click(Sender: TObject);
begin
Edit1.Text := FROW2.ToString ;
end; procedure TForm8.FormActivate(Sender: TObject);
begin
if(Tag=0) then begin
Tag:=1; FRow1:=-1;
FRow2:=-1; ShowG1();
if(g1.RowCount>0) then G1.SelectCell(0,0); // 初始化时,选中G1的第一行
end;
end; procedure TForm8.ShowG1;
var
ss: TStringList;
i: Integer;
begin
ss:=TStringList.Create;
ss.LoadFromFile('c:/g1.txt');
G1.RowCount:=ss.Count;
for i:=0 to ss.Count-1 do G1.Cells[0,i]:=ss[i];
ss.Free;
end; procedure TForm8.ShowG2;
var
ss: TStringList;
i: Integer;
begin
ss:=TStringList.Create;
ss.LoadFromFile('c:/g2'+FRow1.ToString+'.txt');
G2.RowCount:=ss.Count;
for i:=0 to ss.Count-1 do G2.Cells[0,i]:=ss[i];
ss.Free; FRow2:=-1;
if(G2.RowCount>0) then begin
Row2:=0;
G2.SelectCell(0,0);
end;
end; procedure TForm8.Item;
begin
Edit1.Text:=G2.Cells[0,Row2];
end; procedure TForm8.Save;
var
ss:TStringList;
i:Integer;
begin
if(FRow2>=0) and (FRow2<=G2.RowCount-1) then begin
if(Edit1.Text<>G2.Cells[0,FRow2]) then begin
G2.Cells[0,FRow2]:=Edit1.Text; ss:=TStringList.Create;
for i:=0 to G2.RowCount-1 do ss.Add(G2.Cells[0,i]);
ss.SaveToFile('c:/g2'+FRow1.ToString+'.txt'); ss.Clear();
for i:=0 to G1.RowCount-1 do ss.Add(G1.Cells[0,i]);
ss.SaveToFile('c:/g1.txt');
ss.Free;
end;
end;
end; procedure TForm8.SetRow1(const Value: Integer);
begin
if(Value<>FRow1) then begin
Save();
FRow1 := Value;
G1.SelectCell(0,Value);
ShowG2();
end;
end; procedure TForm8.SetRow2(const Value: Integer);
begin
if(Value<>FRow2) then begin
Save();
FRow2 := Value;
Item();
end;
end; procedure TForm8.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Save();
CanClose:=True;
end; procedure TForm8.G1SelectCell(Sender: TObject; const ACol, ARow: Integer;
var CanSelect: Boolean);
begin
// 鼠标点击空白地方的时候,会触发该事件,而ARow的值超出范围
CanSelect:=False;
if(ARow>=0) and (ARow<=G1.RowCount-1) then begin
if(Row1<>ARow) then Row1:=ARow;
CanSelect:=True;
end;
end; procedure TForm8.G2SelectCell(Sender: TObject; const ACol, ARow: Integer;
var CanSelect: Boolean);
begin
CanSelect:=False;
if(ARow>=0) and (ARow<=G2.RowCount-1) then begin
if(Row2<>ARow) then Row2:=ARow;
CanSelect:=True;
end;
end; end.
XE中StringGrid控件还是有很多bug的,在OnSelectCell事件里,鼠标滑过也会触发,若要用ShowMessage或弹出模态窗体,Grid重新聚焦时,会频繁的触发。
在鼠标滑过没有行的Index位置时,也会触发OnSelectCell事件,会出现Index超界,报错。
所以每次都必须保证Grid里有数据,(ARow>=0) and (ARow<=G2.RowCount-1)
XE StringGrid应用(G1属性触发G2)的更多相关文章
- vue data对象添加新属性触发视图
<template> <div class="wrap open"> <a>{{test01.name}}</a> <a> ...
- vue.set动态新增对象属性,触发dom渲染
当我们给一个props或者data中被观测的对象添加一个新的属性的时候,不能直接添加,必须使用Vue.set方法 /** * ==== 选择产品 ==== * 因为vue实现双向数据绑定的机制是数据劫 ...
- (转载)StringGrid常用属性和常用操作
Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...
- (转载)Delphi StringGrid常用属性和常用操作
Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...
- Delphi StringGrid常用属性和常用操作
StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控制网格外观念的属性,以及利用表格的结构响应用户操作的事 ...
- WPF教程(四)RelativeSource属性
我们进行Bingding时,如果明确知道数据源的Name,就能用Source或者ElementName进行绑定,但是有时候我们需要绑定的数据源可能没有明确的Name,此时我们就需要利用Bingding ...
- dispay属性的block,inline,inline-block
转自下面的几位大神: http://www.cnblogs.com/KeithWang/p/3139517.html 总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 bl ...
- display属性及inline-block值(可用来布局)
display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度 <div& ...
- 蚂蚁金服新一代数据可视化引擎 G2
新公司已经呆了一个多月,目前着手一个数据可视化的项目,数据可视化肯定要用到图形库如D3.Highcharts.ECharts.Chart等,经决定我的这个项目用阿里旗下蚂蚁金服所开发的G2图表库. 官 ...
随机推荐
- IaaS vs PaaS vs SaaS
在云计算的早期阶段,企业面临的最大问题是他们是否应该使用公共云服务.如今,几乎所有的组织都在采用一些公共云服务.更重要的问题是企业应该使用哪种云服务:基础设施即服务(IaaS),平台即服务(PaaS) ...
- java中关于length的真确理解~~~~有补充的请跟帖~~~
java中的length到底是个什么东西呢?有人说它是一个类,一个方法,如果是方法,它没有括号, 我只知道它可以得出数组的长度,但是今天遇到一段代码,怎么都解释不通,那就是绝对不会把循环的次数与数组的 ...
- I/O通信模型(BIO,NIO,AIO)
一.传统的BIO 网络编程的基本模型是Client/Server模型,也就是两个进程之间进行相互通信,其中服务端提供位置信息(绑定的IP地址和监听端口),客户端通过连接操作向服务端监听的地址发起连接请 ...
- windows 安装 mysql 5.7.12
看着官网文档搞了半天,也不知所已,最后还是搜索了一下,还是中文好懂 1 下载解压部分略... 2 添加环境变量 在path后加上xx盘:/xx目录/mysql-5.7.12-winx64/bin 3 ...
- 1132 Cut Integer
题意:略. 思路:注意除数可能为0的情况,不然会导致浮点错误. 代码: #include <iostream> #include <string> using namespac ...
- tomcat启动时的java_home和jre_home错误
The JRE_HOME environment variable is not defined correctlyThis environment variable is needed to run ...
- Rest之路 - 搭建开发环境
准备Jersey框架和类库 从官网 (https://jersey.java.net/download.html) 下载最新的zip文件,解压后如下图: lib: 包含Jersey的所有类库. ext ...
- 如何检测 51单片机IO口的下降沿
下降沿检测,说白了就是满足这样一个逻辑,上次检测是1,这次检测是0,就是下降沿. 从这个条件可知,要确保能够正确检测到一个下降沿,负脉冲的宽度,必须大于一个检测周期,当负脉冲宽度小于一个检测周期,就有 ...
- js中的Math
js中的Math Math.round 取最接近的整数 Math.round(-2.7) // -3 Math.ceil 向上取整 Math.ceil(1.1) // 2 Math.floor 向下取 ...
- 2014.8.25 VS新建项目模板消失解决方法
Vs2005 新建项目时windows应用程序模板消失问题解决方法: 1:进入C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\ ...