数据源是逗号分隔的文本文件,没有标题行,也没有行序号字段,数据是标准的二维表格内容。我想在DELPHI 7 中建立表格式的界面,读文本文件数据,并能编辑(增加,删除,修改),能固定第一行,第一列,最好能显示行序号,然后将修改后的数据保存到原来的文本文件中。我是DELPHI 初学者,目前看到TStringGrid ,TF1book,TDBGrid显示的界面是表格形式的,想请教:
在众多控件中,用哪个最合适,最方便(因为我水平比较低)?先谢谢各位热心朋友。
在众多控件中,用哪个最合适,最方便(因为我水平比较低)?先谢谢各位热心朋友。
解决方案 »
- INDY的TIDTCPSERVER在有客户端连接时关闭服务器程序时,总是报线程超时,该如何解决?
- 有关截取字符串
- 如何修改XML中节点“<ID>数值</ID>”的“数值”?加急急急急!
- 求点击题头排序的TListView控件
- 送分,大家快过来!
- 望请指导学习SQL SERVER的问题。HELP ME>...
- 如何在主窗口与About窗之间传输少量数据?
- 为何D6的database destop输table(p5 for windows)中文时要输两遍才上去,第一次是乱码
- 一个类的小问题。
- 不知道错在那儿,实在是太菜了。
- 各位大哥帮我看看这个问题,出错在哪?在线等...........
- 怎样用Delphi构建一个先进先出的队列,在线等 ,急急!请高手进来解答下
读取的话,建议是用TStringList
===用非DELPHI的内置控件,程序编译后,是否还需要这个控件支持,就是一起发布?
自己写一个读写函数就可以了
-------------------------------Delphi 3,4,5,6 Open the file ASGDx.DPK, compile and install the package.
提示
没有advgrid.pas文件编译无法通过,从其他网站下载的也是这个情况。另外,这个控件是要付费的吧?
楼主说的应该是CSV文件,只需要在ODBC中建立一个数据源,在DELPHI中用SELECT * FROM 文件名即可,与操作表相同!
procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);
var
f: TextFile;
i, k: Integer;
rowstr: string;
begin
AssignFile(f, FileName);
Rewrite(f);
with StringGrid do
begin
for i := 1 to rowCount - 1 do //
begin
rowstr := '';
for k := 1 to colCount - 1 do //
(*begin
if k=1 then
//µÚÒ»¸ö ×Ö¶Î
rowstr := cells[k, i]
else
rowstr := rowstr + ',' + cells[k, i];
end;*)
//----------------------------
begin
if k = 1 then
rowstr := cells[k, i] + ',' //
else
if k = colcount - 1 then //
rowstr := rowstr + cells[k, i]
else
rowstr := rowstr + cells[k, i] + ','; //
end;
//---------------------------------------------
Writeln(F, rowstr); //
end;
end;
CloseFile(F);
end;//读
procedure TForm1.Button3Click(Sender: TObject);var
aa, bb: tstringlist;
i, col: integer;
begin
aa := tstringlist.Create;
bb := tstringlist.Create;
if opendialog1.Execute then aa.LoadFromFile(opendialog1.filename); stringgrid1.RowCount := aa.count + 1;
stringgrid1.Cells[0, 0] := 'ÐòºÅ'; for i := 0 to aa.Count - 1 do
begin
for col := 1 to fngetpartcount(aa.strings[i], ',') do
begin
if fngetpartcount(aa.Strings[i], ',') > stringgrid1.ColCount then
stringgrid1.ColCount := fngetpartcount(aa.Strings[i], ',') + 1;
stringgrid1.cells[0, i + 1] := inttostr(i + 1);
stringgrid1.cells[col, i + 1] := fnGetPartString(aa.strings[i], col, ','); end;
end; for i := 1 to stringgrid1.ColCount do
begin
stringgrid1.Cells[i, 0] := 'µÚ' + inttostr(i) + 'ÁÐ';
end; SetOptimalGridCellWidth(stringgrid1, [0..0]); aa.Free;
bb.Free;end;
procedure SetOptimalGridCellWidth(sg: TStringGrid;
ExcludeColumns: TExcludeColumns);
var
i: Integer;
j: Integer;
max_width: Integer;
begin
with sg do
begin
// If the grid's Paint method hasn't been called yet,
// the grid's canvas won't use the right font for TextWidth.
// (TCustomGrid.Paint normally sets this, under DrawCells.)
Canvas.Font.Assign(Font);
for i := 0 to (ColCount - 1) do
begin
if i in ExcludeColumns then
Continue;
max_width := 0;
// Search for the maximal Text width of the current column.
for j := 0 to (RowCount - 1) do
max_width := Math.Max(max_width, Canvas.TextWidth(Cells[i, j]));
// The hardcode of 4 is based on twice the offset from the left
// margin in TStringGrid.DrawCell. GridLineWidth is not relevant.
if max_width > 0 then
ColWidths[i] := max_width + 4
else
ColWidths[i] := DefaultColWidth;
end; { for }
end;
end;
TStringList============
是不是没有可视界面的?只能用代码操作?
function strnget(
const sourStr,slipStr:string;
const posiInt:integer;
const daufStr:string):string;
var
strTemp :string;
intLoop :integer;
begin{截取某个指定字符串后的数据}
strTemp := sourStr;
try
if(sourStr = '') then exit;
if(slipStr = '') then exit; intLoop := 1;
while (intLoop<posiInt) do
begin
inc(intLoop);
strTemp := copy(strPos(PChar(strTemp), PChar(slipStr)), length(slipStr)+1, maxint);
if(strTemp = '') then exit;
end;
intLoop := pos(slipStr, strTemp);
if(intLoop = 0) then intLoop := maxint;
strTemp := copy(strTemp, 1, intLoop-1);
finally
case (strTemp='') of
true: result := daufStr;
else result := strTemp;
end;
end;
end;用法:strnget(源string, string分割字符:如',', 第几个, 默认值);