Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking 2 projects

Status
Not open for further replies.

filipe26

Programmer
Mar 17, 2003
152
PT
Hi i have a problem with a component that have a function wich takes many time to complete and dont let me do another function.So i create another project like a group but to test putting the component in the second project but i dont know how to pass variables through these.
 
Project groups are a simple way of having different projects available for editing at once - it does not provide a method of sharing between projects.

If you're wanting to simply share a unit between projects, then add the unit to both of your projects.

If you're wanting to have this function run concurrently then you can either have the function call either the ProcessMessage or HandleMessage method (consult the help file for details on what these do). However neither of these will allow you to execute another function. To do that, you would need to put your function in it's own thread. Have a look in the help file on threads, and post back here if you need more help.
 
hi i saw the delphi help and i have made a thread unit like this:

unit _thread;

interface

uses
Classes, deACM
,deAudioStreams,deAudioControls,sysutils;

type
Tmeuthread = class(TThread)

private
{ Private declarations }
entrada,saida:String;
protected
procedure Execute; override;
procedure encode;
public
constructor Criar(fichin,fichout:String);

end;

implementation

uses _Main;

constructor TMeuThread.Criar(fichin,fichout:string);
begin
Create(False);
entrada:=fichin; // error in here
saida:=fichout;
FreeOnTerminate := True;
end;



procedure Tmeuthread.Execute;
begin
synchronize(encode);
end;

procedure Tmeuthread.encode;
var
FRIFFIn: TdeRIFFAudioReader;
begin
try
main.FInputFile := TFileStream.Create(entrada, fmOpenRead);
main.FOutputFile := TFileStream.Create(saida, fmCreate);
FRIFFIn := TdeRIFFAudioReader.Create(main.finputfile);
main.FRIFFOut := TdeRIFFAudioWriter.Create(main.FOutputFile);
main.FRIFFOut.Format.Assign(main.deAudioConvertor1.FormatOut);
main.deAudioConvertor1.FormatIn.Assign(FRIFFIn.Format);
main.deAudioConvertor1.Activate;
main.FCurrentChunk := FRIFFIn.GetCurrentChunkAsStream;
main.deAudioConvertor1.ConvertAudioStream(main.FCurrentChunk);
finally
FreeAndNil(main.FCurrentChunk);
FreeAndNil(FRIFFIn);
FreeAndNil(main.FRIFFOut);
FreeAndNil(main.FOutputFile);
end;
end;

end.

the function i want to pass is "encode" but gives me an access violation error in modute rt70 when i try to call in main like this:

procedure Tmain.but2Click(Sender: TObject);
var

fazencode:Tmeuthread;

begin
fazencode.Criar(copy.DestFile,saida);
end;

I put a break in thread unit and the error appears on the line above.

Please help me,thanks.
 
Ok - a few things need some fixing.

First up, in your Tmain.but2Click method, the correct way to initialize any object is like this:

var
fazencode: TMeuthread;
begin
fazencode := TMeuthread.Create(......
end;

I'm sure this will fix your access violation.

 
Hi filipe26,

using threads this way won't help, since you use Synchronize; using synchronize in a thread is nothing more than executing the code in the main VCL thread (the actual application), this means that the app will be busy encoding your file and will not be able to respond to user input (like mouse and keyboard events). if the classes that you use in the encode() procedure are guaranteed threadsafe, I would change your code like this :


unit _thread;

interface

uses
Classes, deACM
,deAudioStreams,deAudioControls,sysutils;

type
Tmeuthread = class(TThread)

private
{ Private declarations }
entrada,saida:String;
protected
procedure Execute; override;
procedure encode;
public
constructor Criar(fichin,fichout:String);

end;

implementation

uses _Main;

constructor TMeuThread.Criar(fichin,fichout:string);
begin
Create(False);
entrada:=fichin;
saida:=fichout;
FreeOnTerminate := True;
end;



procedure Tmeuthread.Execute;
begin
encode;
end;

procedure Tmeuthread.encode;
{no change}
end.

procedure Tmain.but2Click(Sender: TObject);
var

fazencode:Tmeuthread;

begin
fazencode:=Tmeuthread.Criar(copy.DestFile,saida);
fazencode.resume; // start the thread
end;




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top