该如何储存treeview的Data以及读出Data?(100分)

  • 主题发起人 主题发起人 lgq
  • 开始时间 开始时间
L

lgq

Unregistered / Unconfirmed
GUEST, unregistred user!
我用以下代码储存treeview的Data以及读出Data,却不正确。
Pstr=^string;

var p:Pstr;
new(p);
query1.First;
while not query1.Eof do
begin
p^:=query1.FieldByName('xuehao').AsString;
node:=treeview1.Items.AddChildObject(nil,query1.FieldByName
('stud').AsString,p);
query1.Next;
end;
当我用:
Edit2.Text:=TreeView1.Selected.Text;
Edit1.Text:=Pstr(TreeView1.Selected.data)^;
此时Edit2可显示正确的内容,而Edit1却总显示最后一次赋值的Treeview节点的内容。这
是为什么?我该如何储存treeview的Data以及读出Data。
 
这是Help 里的一段:
The following code defines a record type of TMyRec and a record pointer type of PMyRec.

type
PMyRec = ^TMyRec;
TMyRec = record
FName: string;
LName: string;
end;

Assuming these types are used, the following code adds a node to TreeView1
as the last sibling of a specified node. A TMyRec record is associated with
the added item. The FName and LName fields are obtained from edit boxes Edit1
and Edit2. The Index parameter is obtained from edit box Edit3.
The item is added only if the Index is a valid value.

procedure TForm1.Button1Click(Sender: TObject);

var
MyRecPtr: PMyRec;
TreeViewIndex: LongInt;
begin
New(MyRecPtr);
MyRecPtr^.FName := Edit1.Text;
MyRecPtr^.LName := Edit2.Text;
TreeViewIndex := StrToInt(Edit3.Text);
with TreeView1 do
begin
if Items.Count = 0 then
Items.AddObject(nil, 'Item' + IntToStr(TreeViewIndex), MyRecPtr)
else if (TreeViewIndex < Items.Count) and (TreeViewIndex >= 0) then

Items.AddObject(Items[TreeViewIndex], 'Item' + IntToStr(TreeViewIndex), MyRecPtr);
end;
end;

After an item containing a TMyRec record has been added,
the following code retrieves the FName and LName values associated with the item
and displays the values in a label.

procedure TForm1.Button2Click(Sender: TObject);

begin
Label1.Caption := PMyRec(TreeView1.Selected.Data)^.FName + ' ' +
PMyRec(TreeView1.Selected.Data)^.LName;
end;
 
没有什么区别呀!请lha再说得详细一点.
 
要这么辛苦????????
用TreeView的SaveToFile和LoadFromFile不就行了?
 
我用的 C++ Builder 的一段,应该类似

写:
TTreeNode *theNode, *parentNode;
int *p;
theNode = TreeView1->Items->AddChild(parentNode, '显示标题');
p = new int;
*p = 223;
theNode->Data = p;

读:
int *p;
p = (int *)TreeView1->Selected->Data;
 
我左看右看。。上看下看。。原来这个问题不简单。。(反正我没看出来)。

你肯定储存treeview的Data存到数据库中的代码没有问题吗?
 
其实new(p)应该写在循环内。
 
这段代码问题很大。(不好意思)
首先,Delphi 的 string 本来就是指针,何必把它定义成 ^string,然后再把它
用 P^ 转换回来呢?
其次,New 操作写在循环外面,每次赋值都把前次的内容重写了,当然就只有最后
一次的内容了。
如果把 New 操作写在循环内部,在程序退出时还必须逐个释放才行,否则会造成
内存泄漏。
最后,Data 的数据结构最好定义成一个 Record ,不要直接使用 string 。

See it ?
From: BaKuBaKu
 
Sorry ,上次我贴的不太好,你可能看不出来。
touchme_1 说的是对的。
上次我贴的代码是 按一下Button执行一次,包括new(p),
每次都分配新的空间。

象下面这样就行了

type Pstr=^string;
procedure TForm1.Button1Click(Sender: TObject);
var p : Pstr;
begin
query1.First;
while not query1.Eof do
begin
new(p);
p^:=query1.FieldByName('xuehao').AsString;
treeview1.Items.AddObject(nil,query1.FieldByName
('stud').AsString,p);
query1.Next;
end;
end;

因为 没有为 P 开辟新的空间 ,要加入的 Data 都加到第一个Node 上了,
每次加入的Data覆盖了上次的Data!

所以就会和你说的一样:“此时Edit2可显示正确的内容,
而Edit1却总显示最后一次赋值的Treeview节点的内容 ”
 
你可以看看以下程序段:
unit fBHTreeList;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DB, ComCtrls, ExtCtrls, StdCtrls, Grids, DBGrids, Mask, DBCtrls, Buttons,
ToolWin, Menus, ImgList;

type
TfrmBHTreeList = class(TForm)
Panel2: TPanel;
TreeViewMC: TTreeView;
ImageList1: TImageList;
ListBoxBHLen: TListBox;
DBEditMC: TDBEdit;
Label1: TLabel;
Label2: TLabel;
DBEditBH: TDBEdit;
StatusBar1: TStatusBar;
ImageList2: TImageList;
ImageList3: TImageList;
Panel1: TPanel;
Splitter1: TSplitter;
ListBoxTemp: TListBox;
ImageList4: TImageList;
DBGrid1: TDBGrid;
PanelTools: TPanel;
SpeedButton1: TSpeedButton;
SpeedButtonAppend: TSpeedButton;
SpeedButtonDel: TSpeedButton;
SpeedButtonEdit: TSpeedButton;
SpeedButton6: TSpeedButton;
Label3: TLabel;
EditDM: TEdit;
procedure TreeViewMCChange(Sender: TObject; Node: TTreeNode);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TreeViewMCGetImageIndex(Sender: TObject; Node: TTreeNode);
procedure FormShow(Sender: TObject);
procedure SpeedButtonAppendClick(Sender: TObject);
procedure SpeedButtonEditClick(Sender: TObject);
procedure SpeedButtonDelClick(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
fBHFieldName,fMcFieldName:String;
fDataSet:TDataSet;
fTreeViewTitle:string;
PRocedure SetBHTreeView;
Function GetBHIndex(Const BHLen:Integer):Integer;
Function GetDataSetNodeText:String;
Function GetBHIndexLen(Const Index:Integer):Integer;
Procedure SGEtMcBH(Var Mc,BH:String;Node:TTreeNode);
public
{ Public declarations }
PRocedure SetDataSet(ADataSource:TDataSource;Const aBHFieldName,aMcFieldName:String;
Const BHLen:array of Integer;TreeViewTitle:string='编码表');
end;

var
frmBHTreeList: TfrmBHTreeList;

implementation

uses fSetATreeViewBH;

{$R *.DFM}

PRocedure TfrmBHTreeList.SetDataSet(ADataSource:TDataSource;Const aBHFieldName,aMcFieldName:String;
Const BHLen:array of Integer;TreeViewTitle:string='编码表');
Var
i,j,ALen:INteger;
Begin
fDataSet:=aDataSource.DataSEt;
fTreeViewTitle:=TreeViewTitle;
DBGrid1.DataSource:=aDataSource;
DBEditBH.DataSource:=aDataSource;
DBEditMC.DataSource:=aDataSource;
DBEditBH.DataField:=aBHFieldName;
DBEditMc.DataField:=aMcFieldName;

fBHFieldName:=aBhFieldName;
fMcFieldName:=aMcFieldName;

ALen:=0;
ListBoxBHLen.Items.Clear;
For i:=Low(BHLen) to High(BHLen) Do BEgin
ALen:=Alen+BHLen;
ListBOxBHLen.ITems.Add(IntToStr(ALen));
for j:=1 to BHLen do begin
EditDM.Text:=EditDm.Text+'*';
end;
EditDM.Text:=EditDm.Text+' ';
End;
SetBHTreeView;
End;


PRocedure TfrmBHTreeList.SetBHTreeView;
Var
Node: array[0..5] of TTreeNode;
s:String;
BHLenIndex:Integer;
BEgin
TreeViewMC.Items.Clear;
ListBoxTemp.ITems.Clear;
if fDataSet=nil Then Exit;
if Not fDataSet.Active Then Exit;
Node[0]:=TreeViewMC.Items.AddFirst(nil,fTreeViewTitle);
ListBOxTemp.ITems.Add('0');
if fDataSEt.IsEmpty Then Exit;
fDataSet.First;
while NOt fDataSEt.Eof Do Begin
Try
s:=GetDataSetNodeText;
BHLenIndex:=GEtBHIndex(Length(fDataSet[fBHFieldName]));
Except
//
end;
if ListBOxTemp.ITems.Indexof(IntToStr(BHLenIndex))>=0 Then Begin
Node[BHLenIndex+1]:=TreeViewMC.Items.AddChild(Node[BHLenIndex],s);
ListBOxTemp.ITems.Add(IntToStr(BHLenIndex+1));
End;
fDataSet.NExt;
End;
End;


Function TfrmBHTreeList.GetBHIndex(Const BHLen:Integer):Integer;
Begin
Result:=ListBoxBHLen.Items.Indexof(IntToStr(BHLen));
ENd;


procedure TfrmBHTreeList.TreeViewMCChange(Sender: TObject;
Node: TTreeNode);
Var
McStr,BHStr:String;
// Value:TTreeNode;
begin
// Edit1.Text:=IntToStr(treeviewmc.Indent);
// Edit2.Text:=IntToStr(treeviewmc.Selected.Level);
// treeviewmc.Selected.
// node.item.
// fDataSet.Locate(fMcFieldName,Node.TExt,[]);
SGEtMcBH(McStr,BHStr,Node);
fDataSet.Locate(fMcFieldName+';'+fBHFieldName, VarArrayOf([McStr,BHStr]),[]);

StatusBar1.SimpleText:='编码记录数:'+IntToStr(fDataSet.RecNo)+' / '+inttoStr(fDataSEt.RecordCount);
// ToolButtonEdit.Enabled:=((Node<>Nil) and (node.Level>0));
// ToolButtonDel.Enabled:=ToolButtonEdit.Enabled;
SpeedButtonEdit.Enabled:=((Node<>Nil) and (node.Level>0));
SpeedButtonDel.Enabled:=SpeedButtonEdit.Enabled;
end;





procedure TfrmBHTreeList.FormCreate(Sender: TObject);
begin
frmSetATreeViewBH:=TfrmSetATreeViewBH.Create(Self);
fTreeViewTitle:='编码表';
end;

procedure TfrmBHTreeList.FormDestroy(Sender: TObject);
begin
frmSetATreeViewBH.Free;
end;

Function TfrmBHTreeList.GetDataSetNodeText:String;
Begin
REsult:=fDataSet[fMCFieldName]+#13+fDataSet[fBHFieldName];
End;

Function TfrmBHTreeList.GetBHIndexLen(Const Index:Integer):Integer;
Begin
Result:=0;
if index>=ListBoxBHLen.items.count Then Exit;
if Index=0 Then Result:=strtointdef(ListBOxBHLen.items[index],0)
Else
Result:=strtointdef(ListBOxBHLen.items[index],0)-strtointdef(ListBOxBHLen.items[index-1],0)
End;

Procedure TfrmBHTreeList.SGEtMcBH(Var Mc,BH:String;Node:TTreeNode);
Begin
if Node.Level=0 Then Begin
Mc:='';
BH:='';
Exit;
End;
Mc:=Copy(Node.TExt,1,Pos(#13,Node.TExt)-1);
Bh:=Copy(Node.TExt,Pos(#13,Node.TExt)+1,Length(Node.text)-Pos(#13,Node.TExt));
End;


procedure TfrmBHTreeList.TreeViewMCGetImageIndex(Sender: TObject;
Node: TTreeNode);
begin
// if TreeViewMc.Selected<>nil Then
// TreeViewMc.Selected.ImageIndex:=2;
end;

procedure TfrmBHTreeList.FormShow(Sender: TObject);
begin
SetBHTreeView;
end;

procedure TfrmBHTreeList.SpeedButtonAppendClick(Sender: TObject);
Var
ss,BHStr,BHStr2:String;
Node:TTreeNode;
i:Integer;
bookmark:TBOokmark;
begin
if TreeViewMc.Selected=nil Then Begin
if Sender=SpeedButtonEdit Then ss:='请首先选择所要修改的编码!'
else ss:='请首先选择所增加代码的父类!';
Application.MessageBox(pchar(ss),pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
if (treeviewmc.Selected.Level=0) and (Sender=SpeedButtonEdit) Then BEgin
Application.MessageBox('不能进行修改 !',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End
Else if (treeviewmc.Selected.Level>=ListBoxBHLen.Items.Count)
and (Sender=SpeedButtonAppend) Then
Begin
Application.MessageBox(pchar('不能够再增加子编码,只允许有'+inttostr(ListBoxBHLen.Items.Count)+
'级编码!'),pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
frmSetATreeViewBH.EditMC.Text:='';
BHStr:=Inttostr(TreeViewMc.Selected.Count+1);
For i:=Length(BHStr)+1 To GetBHIndexLen(treeviewmc.Selected.Level) DO Begin
BHStr:='0'+BHStr;
End;
frmSetATreeViewBH.EditBH.TExt:=BHStr;

if treeviewmc.Selected.Level=0 Then BEgin
frmSetATreeViewBH.EditSZMc.Text:='';
frmSetATreeViewBH.EditSZBH.TExt:='';
End Else Begin
frmSetATreeViewBH.EditSZMc.TExt:=fDataSet[fMcFieldName];
frmSetATreeViewBH.EditSZBH.TExt:=fDataSet[fBHFieldName];
End;
frmSetATreeViewBH.EditBH.MaxLength:=GetBHIndexLen(treeviewmc.Selected.Level);
frmSetATreeViewBH.LabelBH.Caption:='编号:('+Inttostr(frmSetATreeViewBH.EditBH.MaxLength)+')';
if frmSetATreeViewBH.ShowModal=mrOk Then Begin
BHStr2:=frmSetATreeViewBH.EditSZBH.TExt+frmSetATreeViewBH.EditBH.TExt;
Try
BookMark:=fDataSet.GetBookmark;
if fDataSet.Locate(fBhFieldName,BHStr2,[]) Then Begin
Application.MessageBOx('编号相同,不能够再进行增加! ',
pchar(Application.Title),MB_OK+MB_ICONERROR);
Exit;
End;
Finally
fDataSEt.GotoBookmark(Bookmark);
fDataSEt.FreeBookmark(BOokmark);
End;
fDataSet.Append;
fDataSet[fMcFieldName]:=frmSetATreeViewBH.EditMc.TExt;
fDataSet[fBhFieldName]:=BHstr2;
fDataSet.Post;
TreeViewMC.Items.AddChild(TreeViewMc.Selected,GetDataSetNodeText);
// Node:=TreeViewMC.Items.AddChild(TreeViewMc.Selected,GetDataSetNodeText);
TreeViewMCChange(Sender,TreeViewMc.Selected); //重新设置相应的数据
// TreeViewMc.Selected:=Node;
End;
end;

procedure TfrmBHTreeList.SpeedButtonEditClick(Sender: TObject);
Var
BHLen:Integer;
s:String;
Mc,BH,OldBH,NewBH,sss:String;
ChangeBHOK:INteger;
BookMark:TBookMark;
begin
if TreeViewMc.Selected=nil Then Begin
Application.MessageBox('请首先选择所要修改的编码!',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
if (treeviewmc.Selected.Level=0) Then BEgin
Application.MessageBox('不能进行修改 !',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
BHLen:=GetBHIndexLen(treeviewmc.Selected.Level-1);
s:=fDataSet[fBHFieldName];
SGetMcBH(Mc,BH,treeviewmc.Selected);
frmSetATreeViewBH.EditMc.TExt:=Mc;
frmSetATreeViewBH.EditBH.TExt:=Copy(BH,Length(BH)-BhLen+1,BHLen);
SGetMcBH(Mc,BH,treeviewmc.Selected.Parent);
frmSetATreeViewBH.EditSZMc.TExt:=Mc;
frmSetATreeViewBH.EditSZBH.TExt:=BH;
{ if TreeViewMc.Selected.HasChildren Then BEgin
Application.MessageBox('不能修改有子编码的编号!',pchar(Application.Title),
MB_OK);
End;
frmSetATreeViewBH.EditBH.ReadOnly:=TreeViewMc.Selected.HasChildren;
}
frmSetATreeViewBH.EditBH.MaxLength:=GetBHIndexLen(treeviewmc.Selected.Level-1);
frmSetATreeViewBH.LabelBH.Caption:='编号:('+Inttostr(frmSetATreeViewBH.EditBH.MaxLength)+')';
if frmSetATreeViewBH.ShowModal=mrOk Then Begin
NEwBH:=frmSetATreeViewBH.EditSZBH.TExt+frmSetATreeViewBH.EditBH.TExt;
OldBH:=fDataSet[fBhFieldName];
if NewBH<>OldBH THen Begin
Try
BookMark:=fDataSet.GetBookmark;
if fDataSet.Locate(fBhFieldName,NewBH,[]) Then Begin
Application.MessageBOx('存在相同的新编号,不能够再进行修改! ',
pchar(Application.Title),MB_OK+MB_ICONERROR);
Exit;
End;
Finally
fDataSEt.GotoBookmark(Bookmark);
fDataSEt.FreeBookmark(BOokmark);
End;
End;
fDataSet.EDit;
fDataSet[fMcFieldName]:=frmSetATreeViewBH.EditMc.TExt;
if TreeViewMc.Selected.HasChildren Then BEgin
if OldBH<>NewBH THen Begin
ChangeBHOK:=Application.MessageBox('是否将所有的子代码同时进行修改?',pchar(Application.Title),
MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2);
if ChangeBHOK=IDYES Then Begin
fDataSet.Post;
fDataSet.First;
while fDataSet.Locate(fBHFieldName,OldBH,[loPartialKey]) Do Begin
sss:=fDataSet[fBHFIeldName];
if pos(OldBH,sss)=1 Then Begin
fDataSEt.Edit;
fDataSet[fBHFIeldName]:=NewBH+Copy(sss,Length(OldBH)+1,Length(sss)-Length(OldBH));
fDataSEt.Post;
End;
fDataSet.Next;
End;
SetBHTreeView;
Exit;
ENd
Else Begin
fDataSet.Cancel;
Exit;
End;
End;
End Else
fDataSet[fBhFieldName]:=frmSetATreeViewBH.EditSZBH.TExt+frmSetATreeViewBH.EditBH.TExt;
fDataSet.Post;
TreeViewMC.Selected.text:=GetDataSetNodeText;
End;
end;

procedure TfrmBHTreeList.SpeedButtonDelClick(Sender: TObject);
Var
DeleOk:INteger;
McStr,BHStr:String;
begin
if TreeViewMc.Selected=nil Then Begin
Application.MessageBox('请首先选择所要删除的编码名称!',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
if TreeViewMc.Selected.HasChildren Then BEgin
Application.MessageBox('不能删除带有子编码的名称!',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
if treeviewmc.Selected.Level=0 Then BEgin
Application.MessageBox('不能删除编码的说明 !',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;

SGEtMcBH(McStr,BHStr,treeviewmc.Selected);
// ShowMessage(McStr+':'+BhStr);
{ if DataM_YLF.GetHaveBmLY(BhStr) Then Begin
Application.MessageBox('本单位已经存在人员,不能删除此编码!',pchar(Application.Title),
MB_OK+MB_ICONERROR);
Exit;
End;
}
DeleOk:=Application.MessageBox('是否确实要将当前的编码删除? ',pchar(Application.title),
MB_OkCancel+MB_ICONQUESTION+MB_DEFBUTTON2);
if DeleOk=IDOK Then BEgin
fDataSet.Delete;
TreeViewMc.Selected.Delete;
end;
end;

procedure TfrmBHTreeList.SpeedButton6Click(Sender: TObject);
Var
sStr:String;
i:Integer;
IsFind:Boolean;
begin
sStr:=INputBOx(Application.Title,'请输入所查询的编码代码或名称:','');
if sStr<>'' Then Begin
if (sStr[1]>='0') and (sStr[1]<='9') Then
IsFind:=fDataSet.Locate(fBHFieldName,sStr,[loPartialKey])
Else IsFind:=fDataSet.Locate(fMcFieldName,sStr,[loPartialKey]);
if Not IsFind Then Begin
ShowMessage('没有找到相应的编码! ');
Exit;
End;
For i:=0 to TreeViewMc.Items.Count-1 Do Begin
if TreeViewMc.Items.Text=GetDataSetNodeText Then Begin
TreeViewMc.Selected:=TreeViewMc.Items;
Exit;
End;
End;
End;
end;

procedure TfrmBHTreeList.SpeedButton1Click(Sender: TObject);
begin
Close;
end;

end.
unit fDataCount;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
AxCtrls, OleCtrls, vcf1, ExtCtrls, ComCtrls,
StdCtrls, Grids, DBGrids, Db, mxstore, mxDB, DBTables, mxtables, mxgrid,
mxpivsrc, TeEngine, Series, TeeProcs, Chart, mxgraph,
Menus, Buttons, PrintAtOnces, swDBPanl, sStatPan,
SHELLAPI, ToolWin, ReportControl, TB97Ctls,cBmBhTreeList, ActnList,
ImgList;

type
TfrmDataCount = class(TForm)
DecisionQuery1: TDecisionQuery;
DataSource1: TDataSource;
FontDialog1: TFontDialog;
PopupMenuReport: TPopupMenu;
NmnuAllData: TMenuItem;
N7: TMenuItem;
N3: TMenuItem;
N2: TMenuItem;
N11: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
NmnuReport1: TMenuItem;
NmnuReport_Excel: TMenuItem;
NmnuReport_CELL: TMenuItem;
NmnuReport_eReport: TMenuItem;
NmnuReport_Word: TMenuItem;
N6: TMenuItem;
TableDW_L: TTable;
NmnuDataPrintIsEmpty: TMenuItem;
TableDW_LStringField: TStringField;
TableDW_LStringField2: TStringField;
NmnuIsCompress: TMenuItem;
TableDW_LField: TStringField;
TableDW_LField2: TStringField;
PopupMenuTitle: TPopupMenu;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
Bevel1: TBevel;
ToolbarButton977: TToolbarButton97;
ToolbarButton971: TToolbarButton97;
ToolbarButton9719: TToolbarButton97;
ToolbarButton9715: TToolbarButton97;
SpeedButton3: TSpeedButton;
MemoCountCFG: TMemo;
Panel1: TPanel;
LabelTitle: TLabel;
DBGrid1: TDBGrid;
TreeViewBmBh: TTreeView;
SplitterBmBh: TSplitter;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ActionList1: TActionList;
ActionPreView: TAction;
ImageList1: TImageList;
ToolButton3: TToolButton;
ActionFont: TAction;
ToolButton4: TToolButton;
ActionClose: TAction;
ToolButton5: TToolButton;
PrintAtOnce1: TPrintAtOnce;
Panel2: TPanel;
ComboBox1: TComboBox;
DateTimePickerEnd: TDateTimePicker;
Label6: TLabel;
DateTimePickerStart: TDateTimePicker;
Label5: TLabel;
procedure FormCreate(Sender: TObject);
procedure ToolbarButton973Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure NmnuAllDataClick(Sender: TObject);
procedure DecisionQuery1AfterOpen(DataSet: TDataSet);
procedure DecisionQuery1AfterClose(DataSet: TDataSet);
procedure NmnuReport1Click(Sender: TObject);
procedure TableDW_LAfterScroll(DataSet: TDataSet);
procedure TableDW_LFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
procedure TableDW_LCalcFields(DataSet: TDataSet);
procedure NmnuReport_eReportClick(Sender: TObject);
procedure NmnuReport_WordClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
procedure MenuItem2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ActionPreViewExecute(Sender: TObject);
procedure ActionFontExecute(Sender: TObject);
procedure ActionCloseExecute(Sender: TObject);
private
{ Private declarations }
fBmBhTreeList:TBmBhTreeList;
fSQL:String;
public
{ Public declarations }
end;

var
frmDataCount: TfrmDataCount;

implementation

uses fDataM_DT;

//uses fSetShowGridField, fSetPrintDBGrid, fYLFMain, fTuReport, fDataM_YLF,
// fCount1, fCount2, fCount3, fCount4, fCount5;

{$R *.DFM}
{$B-}
procedure TfrmDataCount.FormCreate(Sender: TObject);
Var
i:Integer;
begin
Try
fBmBhTreeList:=TBmBhTreeList.Create;
DateTimePickerStart.Date:=Date;//EncodeDate(gYLFSYS.DataYear,1,1);
DateTimePickerEnd.Date:=Date;//EncodeDate(gYLFSYS.DataYear,12,31);
Except
//
End;
// frmYLFMain.ListBoxCreateFormName.Items.add(Self.Name);
MemoCountCFG.Lines.LoadFromFile(ExtractFilePath(Application.ExeName)+'Count.CFG');
i:=0;
ComboBox1.Items.CLear;
while i<MemoCountCFG.Lines.Count Do Begin
ComboBox1.Items.Add(MemoCountCFG.Lines);
inc(i,10);
End;
end;

procedure TfrmDataCount.ToolbarButton973Click(Sender: TObject);
begin
Close;
end;

procedure TfrmDataCount.FormShow(Sender: TObject);
begin
TreeViewBmBh.OnChange:=nil;
Try
fBmBhTreeList.SetData(DataM_DT.DataS_LB_L,
DataSource1,
'代码','名称','代码',
TreeViewBmBh,[2,1,1],'靖江市广播电视局分类编码表');

Except
//
End;
Try
ComboBox1Change(Sender);
Except
//
End;
end;

procedure TfrmDataCount.FormDestroy(Sender: TObject);
begin
fBmBhTreeList.Free;
end;

procedure TfrmDataCount.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;

procedure TfrmDataCount.NmnuAllDataClick(Sender: TObject);
begin
TMenuItem(Sender).checked:=Not TMenuItem(Sender).checked;
end;

procedure TfrmDataCount.DecisionQuery1AfterOpen(DataSet: TDataSet);
begin
//// TableDW_L.Open;
//// SplitterBmBh.Visible:=(DataSet.Fields.FindField('代码')<>nil);
//// TreeViewBmBh.Visible:=(DataSet.Fields.FindField('代码')<>nil);
//// if DataSet.Fields.FindField('代码')<>nil Then
//// DataSet.Fields.FindField('代码').Visible:=False;
// if DataSet.Fields.FindField('名称')<>nil Then
// DataSet.Fields.FindField('名称').DisplayWidth:=gYLFCFG.BmMcDisplayWidth;
end;

procedure TfrmDataCount.DecisionQuery1AfterClose(DataSet: TDataSet);
begin
DecisionQuery1.Filtered:=False;
DecisionQuery1.Filter:='';
TableDW_L.CLose;
// TreeViewBmBh.OnChange:=nil;
end;

procedure TfrmDataCount.NmnuReport1Click(Sender: TObject);
Var
s,s1:String;
begin
Try
TableDW_L.Filtered:=True;
if ComboBox1.ItemIndex<0 Then Exit;
s:=Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+TMenuitem(Sender).Tag]);
s1:=MemoCountCFG.Lines[ComboBox1.ItemIndex*10+3];
Finally
TableDW_L.Filtered:=False;
if TreeViewBmBh.Visible THen fBmBhTreeList.RefreshData;
ENd;
end;

procedure TfrmDataCount.TableDW_LAfterScroll(DataSet: TDataSet);
Var
s:String;
begin
if DataSet.IsEmpty Then Exit;
if ComboBox1.ItemIndex<0 Then Exit;
if Not DataSet.Filtered THen Exit;
s:=MemoCountCFG.Lines[ComboBox1.ItemIndex*10+3];
if (s[1]='1') or (s[1]='2') THen Begin
if DecisionQuery1.Fields.FindField('代码')<>nil Then
Begin
DecisionQuery1.Filtered:=True;
DecisionQuery1.Filter:='代码='+#39+DataSet['代码']+'*'+#39;
End;
End;
end;

procedure TfrmDataCount.TableDW_LFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
Var
s:String;
begin
if ComboBox1.ItemIndex<0 Then Exit;
s:=MemoCountCFG.Lines[ComboBox1.ItemIndex*10+3];
if s='' THen Exit;
if DataSet['代码']=NULL THen Exit;
if (s[1]='1') Then Begin
Accept:=Length(DataSet['代码'])=3;
End;
if (s[1]='2') THen Begin
Accept:=Length(DataSet['代码'])=5;
End;//
end;

procedure TfrmDataCount.TableDW_LCalcFields(DataSet: TDataSet);
begin
Try
if DataSet['代码']<>NULL Then Begin
// if Length(DataSet['代码'])=5 Then
// DataSet['单位名称']:=DataM_YLF.wwTable_DW_L.lookup('代码',Copy(DataSet['代码'],1,3),'名称');
if Length(DataSet['代码'])=3 Then
DataSet['单位名称']:=DataSet['名称'];
if DataSet['单位名称']<>NULL Then
DataSet['单位部门名称']:=DataSet['单位名称']+' : '+DataSet['名称']
Else
DataSet['单位部门名称']:=DataSet['名称'];
ENd;
Except
//
End;
end;

procedure TfrmDataCount.NmnuReport_eReportClick(Sender: TObject);
Var
FileName:String;
a:String;
i:Integer;
begin
if ComboBox1.ItemIndex<0 Then Exit;

a:=MemoCountCFG.Lines[ComboBox1.ItemIndex*10+8];
FileName:=ExtractFilePath(Application.ExeName);

for i:=0 to TableDW_L.FieldCount-1 Do Begin
Try
// if Not TableDW_L.Fields.IsNull Then
// ReportRunTime1.SetvarValue(TableDW_L.Fields.FieldName,TableDW_L.Fields.AsString);
Except
//
End;
End;

for i:=0 to DecisionQuery1.FieldCount-1 Do Begin
Try
// if Not DecisionQuery1.Fields.IsNull Then
// ReportRunTime1.SetvarValue(DecisionQuery1.Fields.FieldName,DecisionQuery1.Fields.AsString);
Except
//
End;
End;
Try
TableDW_L.DisableControls;
DecisionQuery1.DisableControls;
Finally
TableDW_L.EnableControls;
DecisionQuery1.EnableControls;
End;
end;

procedure TfrmDataCount.NmnuReport_WordClick(Sender: TObject);
Var
RepFileName:String;
InstanceID : THandle;
begin
if NmnuReport_Word.Hint='' THen Exit;
RepFileName:=ExtractFilePath(Application.ExeName)+NmnuReport_Word.Hint;
InstanceID := ShellExecute(0,nil,'wordrep.exe',@RepFileName[1],nil,SW_HIDE);
if InstanceID < 32 then Begin
ShowMessage('不能执行WordRep报表文件');
End;
End;

procedure TfrmDataCount.MenuItem1Click(Sender: TObject);
begin
LabelTitle.caption:= InputBox(Application.Title,'请输入所要设置的标题名称:', LabelTitle.caption);
end;

procedure TfrmDataCount.MenuItem2Click(Sender: TObject);
begin
FontDialog1.Font:=LabelTitle.Font;
if FontDialog1.Execute then LabelTitle.Font:=FontDialog1.Font;
end;

procedure TfrmDataCount.ComboBox1Change(Sender: TObject);
Var
aParam:TParam;
SQLStr:String;
aPos,i:Integer;
begin
if ComboBox1.ItemIndex<0 Then Exit;
Try
Try
{ DecisionQuery1.Close;
//'1' 为统计
SQLStr:=MemoCountCFG.Lines[ComboBox1.ItemIndex*10+1];
LabelTitle.Caption:=ComboBox1.Items[ComboBox1.ItemIndex];
aPos:=Pos('TZ.DB',UpperCase(SQLStr));
// if aPos>0 Then Insert(Trim(IntToStr(gYLFSYS.DataYear)),SQLStr,aPos);

aPos:=Pos(':MDATAYEAR',UpperCase(SQLStr));
if aPos>0 Then Begin
Delete(SQLSTr,apos,Length(':MDATAYEAR'));
// Insert(Trim(IntToStr(gYLFSYS.DataYear)),SQLStr,aPos);
End;
DecisionQuery1.SQL.TExt:=SqlStr;
fSQL:='';
fSQL:=SqlStr;
for i:=0 to 9 Do fSQL:=fSQL+MemoCountCFG.Lines[ComboBox1.ItemIndex*10+i]+#13;
// for i:=4 to 8 DO Begin
NmnuReport1.Enabled:=(Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+4])<>'');
NmnuReport_EXCEL.Enabled:=(Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+5])<>'');
NmnuReport_WORD.Enabled:=(Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+6])<>'');
NmnuReport_CELL.Enabled:=(Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+7])<>'');
NmnuReport_eReport.Enabled:=(Trim(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+8])<>'');

NmnuReport1.Hint:=(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+4]);
NmnuReport_EXCEL.Hint:=(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+5]);
NmnuReport_WORD.Hint:=(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+6]);
NmnuReport_CELL.Hint:=(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+7]);
NmnuReport_eReport.Hint:=(MemoCountCFG.Lines[ComboBox1.ItemIndex*10+8]);
// ENd;
}
aParam:=DecisionQuery1.Params.FindParam('mStartDate');
if aParam<>nil Then
aParam.AsDate:=DateTimePickerStart.Date;

aParam:=DecisionQuery1.Params.FindParam('mEndDate');
if aParam<>nil Then
aParam.AsDate:=DateTimePickerEnd.Date;

aParam:=DecisionQuery1.Params.FindParam('mDataYear');
// if aParam<>nil Then
// aParam.AsInteger:=gYLFSYS.DataYear;
Finally
DecisionQuery1.OPen;
End;
Except
//
End;
end;

procedure TfrmDataCount.ActionPreViewExecute(Sender: TObject);
begin
PrintAtOnce1.Preview;
end;

procedure TfrmDataCount.ActionFontExecute(Sender: TObject);
begin
FontDialog1.Font:=DBGrid1.Font;
if FontDialog1.Execute then DBGrid1.Font:=FontDialog1.Font;
end;

procedure TfrmDataCount.ActionCloseExecute(Sender: TObject);
begin
Close;
end;

end.
 
BaKuBaKu:
1.如果string 本来就是指针,那么这段代码怎么写?
2.New 操作写在循环内部,在程序退出时还必须逐个释放才行,否则会造成
内存泄漏。我只使用了p一个指针,又何必逐个释放?
3.使用Record我觉得没什么区别,请问区别在哪儿?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
928
SUNSTONE的Delphi笔记
S
后退
顶部