首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从备注框逐行拉取文本

问从备注框逐行拉取文本
EN

Stack Overflow用户
提问于 2012-04-07 04:26:30
回答 2查看 4.4K关注 0票数 3

我需要查看大量数据,这些数据存储在Memo字段中的paradox表中。我需要逐行处理此数据,并处理每一行。

如何告诉Delphi逐个获取memo字段中的每一行?

我可以使用#13#10作为分隔符吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-07 04:33:29

假设memo字段中的内容使用#13#10作为行分隔符,那么我将使用TStringList和非常有用的Text属性将memo字段文本拆分为单独的行:

代码语言:javascript
复制
var
  StringList: TStringList;
  Line: string;
.....
StringList.Text := MemoFieldText;
for Line in StringList do
  Process(Line);

即使您的备注字段使用Unix换行符,此代码也可以正确解释备注字段。

票数 4
EN

Stack Overflow用户

发布于 2012-04-07 04:52:15

这取决于字段在Paradox中的实际声明方式。如果是TMemoField,那就很简单了:

代码语言:javascript
复制
var
  SL: TStringList;
  Line: string;
begin
  SL := TStringList.Create;
  try
    SL.Text := YourMemoField.GetAsString;
    for Line in SL do
     // Process each line of text using `Line`
  finally
    SL.Free;
  end;
end;

如果它是一个TBlobField,它就有点复杂了。您需要使用TBlobStream读取memo字段,并将该流的内容加载到TStringList中

代码语言:javascript
复制
// For Delphi versions that support it:
procedure LoadBlobToStringList(const DS: TDataSet; const FieldName: string;
  const SL: TStringList);
var
  Stream: TStream;
begin
  Assert(Assigned(SL), 'Create the stringlist for LoadBlobToStringList!');
  SL.Clear;
  Stream := DS.CreateBlobStream(DS.FieldByName(FieldName), bmRead);
  try
    SL.LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;

// For older Delphi versions that do not have TDataSet.CreateBlobStream
procedure LoadBlobToStringList(const DS: TDataSet; const TheField: TField; 
  const SL: TStringList);
var
  BlobStr: TBlobStream;
begin
  Assert(Assigned(SL), 'Create the stringlist for LoadBlobToStringList!');
  SL.Clear;
  BlobStr := TBlobStream.Create(DS.FieldByName(TheField), bmRead);
  try
    SL.LoadFromStream(BlobStr);
  finally
    BlobStr.Free;
  end;
end;

// Use it
var
  SL: TStringList;
  Line: string;
begin
  SL := TStringList.Create;
  LoadBlobToStringList(YourTable, YourMemoFieldName, SL);
  for Line in SL do
    // Process each Line, which will be the individual line in the blob field

  // Alternatively, for earlier Delphi versions that don't support for..in
  // declare an integer variable `i`
  for i := 0 to SL.Count - 1 do
  begin
    Line := SL[i];
    // process line of text using Line
  end;
end;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10048868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档