Posted: Wed Nov 24, 2010 4:27 pm
Are the character, paragraph and line count functions tread-safe ? Thanks in advance.
Support forums for TRichView, ScaleRichView, Report Workshop and RVMedia components
https://trichedit.com/forums/
Code: Select all
function GetParaCount(RVData: TCustomRVData): Integer;
var i, r, c, StyleNo: Integer;
table: TRVTableItemInfo;
EmptyPara: Boolean;
ListNo, ListLevel, StartFrom: Integer;
Reset: Boolean;
begin
Result := 0;
EmptyPara := True;
for i := 0 to RVData.ItemCount-1 do begin
if RVData.IsParaStart(i) then begin
if not EmptyPara then
inc(Result);
EmptyPara := True;
end;
StyleNo := RVData.GetItemStyle(i);
if StyleNo=rvsListMarker then begin
RVData.GetListMarkerInfo(i,ListNo, ListLevel, StartFrom, Reset);
if (ListNo>=0) and (ListNo<RVData.GetRVStyle.ListStyles.Count) and
(ListLevel>=0) and (ListLevel<RVData.GetRVStyle.ListStyles[ListNo].Levels.Count) and
RVData.GetRVStyle.ListStyles[ListNo].Levels[ListLevel].UsesFont then
EmptyPara := False
end
else if RVData.GetItem(i) is TRVLabelItemInfo then begin
if Trim(TRVLabelItemInfo(RVData.GetItem(i)).Text)<>'' then
end
else if StyleNo>=0 then begin
if Trim(RVData.GetItemText(i))<>'' then
EmptyPara := False;
end
else if StyleNo=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(i));
for r := 0 to table.RowCount-1 do
for c := 0 to table.ColCount-1 do
if table.Cells[r,c]<>nil then
inc(Result, GetParaCount(table.Cells[r,c].GetRVData));
end;
end;
if not EmptyPara then
inc(Result);
end;
Code: Select all
lblParaCount.Caption := IntToStr(GetParaCount(RichViewEdit1.RVData));
Code: Select all
...
if RVData.GetItemStyle(RVData.DrawItems[i].ItemNo)=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(RVData.DrawItems[i].ItemNo));
for r := 0 to table.RowCount-1 do
for c := 0 to table.ColCount-1 do
if table.Cells[r,c]<>nil then
inc(Result, GetLineCount(TCustomRVFormattedData(table.Cells[r,c].GetRVData)));
...
Code: Select all
function GetCurrentLine(rve: TCustomRichViewEdit): Integer;
var
CurRVData: TCustomRVFormattedData;
CurDItemNo: Integer;
CurDOffs: Integer;
function DoGetCurrentLine(RVData: TCustomRVFormattedData; var LineNo: Integer): Boolean;
var i,r,c: Integer;
table: TRVTableItemInfo;
begin
Result := False;
for i := 0 to RVData.DrawItems.Count-1 do begin
if RVData.DrawItems[i].FromNewLine then
inc(LineNo);
Result := (RVData=CurRVData) and (i=CurDItemNo);
if Result then
exit;
if RVData.GetItemStyle(RVData.DrawItems[i].ItemNo)=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(RVData.DrawItems[i].ItemNo));
for r := 0 to table.RowCount-1 do
for c := 0 to table.ColCount-1 do
if table.Cells[r,c]<>nil then begin
Result := DoGetCurrentLine(TCustomRVFormattedData(table.Cells[r,c].GetRVData), LineNo);
if Result then
exit;
end;
end;
end;
end;
begin
CurRVData := rve.TopLevelEditor.RVData;
CurRVData.Item2DrawItem(rve.TopLevelEditor.CurItemNo,
rve.TopLevelEditor.OffsetInCurItem, CurDItemNo, CurDOffs);
Result := 0;
DoGetCurrentLine(rve.RVData, Result);
end;