BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Issues with COM and threads

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Richard Teller
Guest





PostPosted: Sun Jan 23, 2005 11:30 pm    Post subject: Issues with COM and threads Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.