我们可以重写一行文本文件,然后保存并关闭它吗?
例如,我需要重写第一行,并保留所有其他行.有没有这样做的功能,还是我必须在更改单行后复制整个文件?
我的文件包含多个thaus和行,我只需要更改第一行.
文件示例:
test;test1;test2
other;other;other
other;other;other
x1000
Run Code Online (Sandbox Code Playgroud)
然后
something;something;something
other;other;other
other;other;other
x1000
Run Code Online (Sandbox Code Playgroud)
明白了吗?我只想保留我的文件,但改变第一行.我可以复制整个文件并在我更改第一行后粘贴它,但我想知道是否有一个方法已经包含在delphi中只能更改文本文件中的特定行.谢谢!
我在互联网上找不到^运算符的含义.
那么在这个例子中^意味着什么:
P = PChar(s);
While P^ <> #0 do
begin
//do something
end;
Run Code Online (Sandbox Code Playgroud)
#0例如,是表示字符串结尾的字符.但我无法在互联网上找到^.有人可以解释一下吗?
我有一个字符串网格,用户可以在其中更改列的颜色.我将颜色存储在一个字符串中,它看起来像是:columnToColor:= '1;233,233,233'1是列233; 233; 233是rgb颜色; 每次我必须改变颜色时我都会改变这个字符串.它永远不会包含多个列和一种颜色
在我的绘画中,我这样做:
color := Explode(';',columnToColor); //this will return an array
if (length(color)-1 >= 0) then
begin
if TryStrToInt(color[0], val) then
begin
if aCol = StrToInt(color[0]) then
begin
cellText := grid.Cells[aCol,aRow];
grid.Canvas.Brush.Color := TColor(RGB(StrToInt(color[1]),StrToInt(color[2]),StrToInt(color[3])));
rec := grid.CellRect(aCol,aRow);
grid.Canvas.FillRect(rec);
grid.Canvas.TextOut(rec.Left,rec.top,cellText);
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我正在使用被攻击的StringGrid类从另一个过程调用invalidateCol:
With TCustomStringGrid(grid) do
InvalidateCol(grid.col)
Run Code Online (Sandbox Code Playgroud)
当我只更改一种列颜色时,这种方法有效.我可以自由地滚动网格,它仍然会有良好的列颜色.但是当我改变另一列的颜色时,颜色会在它们仍然可见时显示出来.一旦我水平滚动并返回列,只有最后一个彩色列被着色,其他颜色被设置为默认颜色.颜色仅保留在最后一个彩色列上.因此,如果我为2列着色并单击第一列,则单元格的颜色将设置为默认值.我水平滚动整列1设置为默认颜色.只有第二列才能保持其颜色.
我该如何解决这个问题?