witam,
piszę program, który pobiera dane z exela i mam mały problem z wątkeim.
Jak robię funkcję do pobierania danych w programie głównym, to jest ok, ale jak chcę ją zrobić w wątku, to wywala błąd. Mógłby ktoś przejrzeć kod i znaleźć błąd, bo ja juz ze 2 godz sie męcze... Wyskakuje błąd, że operacja GetActiveOleObject jest niedostępna. Jak to ominąć?
otokod:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw,comobj, Spin;
type
pobean = class(TThread)
private
function aa(file_path:string):string;
protected
procedure Execute; override;
end;
const
xlChart=-4109;
xlWorksheet=-4167;
xlWBATWorksheet=-4167;
xlWBATChart=-4109;
xlPortrait=1;
xlLandscape=2;
xlPaperA4=9;
xlBottom=-4107;
xlLeft=-4131;
xlRight=-4152;
xlTop=-4160;
xlHAlignCenter=-4108;
xlVAlignCenter=-4108;
xlThick=4;
xlThin=2;
implementation
uses unit1;
procedure pobean.Execute;
begin
showmessage(aa('C:\praca_dane\kopie robocze\Przejsciowyeblok.xls'));
end;
function pobean.aa(file_path:string):string;
var
ExcelApp:OleVariant;
w,k:Integer;
begin
try
ExcelApp:=GetActiveOleObject('Excel.Application');
except
try
ExcelApp:=CreateOleObject('Excel.Application');
except
ShowMessage('Excel nie jest zainstalowany w Twoim komputerze lub jest uszkodzony!');
Exit;
end;
end;
ExcelApp.Workbooks.Open(file_path);
Result:=ExcelApp.Cells[1,2].Value;
end;
end.