 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Richard Teller Guest
|
Posted: Sun Jan 23, 2005 11:30 pm Post subject: Issues with COM and threads |
|
|
Is anyone aware of an issue whereby COM items are "lost track of" when
running in another thread?
In a thread I've created to fill a TStringGrid with data from an Excel sheet
.....
Many thanks for any help.
Richard Teller
/////////////////////////////////////////////////////////////////
constructor TFillGridThread.Create(AGrid: TStringGrid; nWorksheet: Integer);
var
Unknown: IUnknown;
Res: HResult;
begin
inherited Create(True);
Res := GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if Res = MK_E_UNAVAILABLE then begin
Excel := nil;
FreeOnTerminate := True;
Terminate;
end
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(ExcelApplication, Excel));
FGrid := AGrid;
FRows := FGrid.RowCount - 1;
FCols := FGrid.ColCount - 1;
FThisWorksheet := Excel.Workbooks.Item[1].Worksheets.Item[nWorksheet] as
ExcelWorkSheet;
// AT THIS POINT I CAN READ VALUES FROM FTHISWORKSHEET FINE
FreeOnTerminate := False;
Resume;
end;
end;
/////////////////////////////////////////////////////////////////
procedure TFillGridThread.Execute;
begin
// AT THIS POINT ALTHOUGH FWORKSHEET IS THE SAME ADDRESS
// .CELLS IS NOW NIL AND NOTHING CAN BE READ
FRow := 1;
while FRow <= FRows do begin
FCol := 1;
while FCol <= FCols do begin
Synchronize(FillCell);
inc(FCol);
end;
inc(FRow);
end;
end;
/////////////////////////////////////////////////////////////////
procedure TFillGridThread.FillCell;
begin
// FGrid.Cells[FCol, FRow] := Format('r%dc%d',[FRow,FCol]); // WORKS FINE
FGrid.Cells[FCol, FRow] := FThisWorksheet.Cells.Item[FRow, FCol].Text; //
FAILS
end;
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|