Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   create richtext at runtime, in web app (http://www.delphipages.com/forum/showthread.php?t=207519)

aberbotimue 10-08-2009 01:45 PM

create richtext at runtime, in web app
 
Hi all...

Can anyone point me in the right direction..

I am running a very quick cgi web application.. but require a print out as an rtf..

in a stand alone app I drop the richtext componant on, and it does what it needs, and then prints, like i want it to.

in the web app, I have to create it at run time.. so I have

Code:


with TRichedit.Create(self) do
try
  Visible := false;
  lines.loadfromfile('c:\formations\testfile.rtf');
  // Print('Printer');
finally
  Free;
end;

this gives me an error like

Code:

Internal Application Error
 
Control '' has no parent window

after some time with my good freind google, I found loads saying its about allocating an appropriate parent

so I added

Code:

  parent := self;
 
and tried
 
  parent := nil;
 
even tried  parent := application.webform;

all giving me compile errors.. as you may have guessed, i am a weekend coder, not doing this day in day out...

can anyopne give me that special line I need!

Cheers all

Aber

aberbotimue 10-20-2009 02:54 PM

Still stuck on this one..
 
I have moved to some of the other code else where, but I have to come back to this one.. any one got any ideas?

its basicly creating a visual comonant on a non visual form I think.. as there isn't a parent window?

nester261 10-20-2009 06:27 PM

Create it something like this:

Code:

var
  RichEdit1: TRichEdit;
begin
  RichEdit1 := TRichEdit.Create(Self);
  with RichEdit1 do
  begin
    Name := 'RichEdit1';
    Parent := Self;
    Left := 208;
    Top := 224;
    Width := 185;
    Height := 89;
    Lines.Clear;
    Lines.Add('RichEdit1');
    TabOrder := 0;
  end;
end;


aberbotimue 10-21-2009 10:35 PM

Tried that one!
 
Thanks for the reply.. Thats one of the versiuons I already tried..

Although, I killed the function, and built it again, setting all the properties you sugest, but get the original issue using "self"

[DCC Error] codebase.pas(299): E2010 Incompatible types: 'TWinControl' and 'TWebModule1'

I am doing it from within a webmodule, and that seems to be my issue..

Any thoughts?

nester261 10-22-2009 01:57 AM

OK - never actually used a TWebModule in Delphi before as never had the need.

I tried the code from a WebModule and yes it does give the Incompatible Types message but if you change the Parent := Self to Nil then it should be ok, and actually compiled fine for me.

I see though that you say you have tried using nil as the parent? What Error message/s did you receive?

aberbotimue 10-22-2009 01:37 PM

Cast the webmodual to 'TWinControl' somhow?
 
As you say, compiles, but when you then create the componant, without a parent, you get a runtime error of

Code:


Internal Application Error

Control '' has no parent window

seems to imply that the componant requires a parent to live!! I was pondering if one could Cast the webmodual to 'TWinControl' somhow? but wouln't know how to do that?

Jasser 10-22-2009 03:29 PM

You don't really need a richedit to print an rtf file. Please see:

http://www.swissdelphicenter.ch/en/showcode.php?id=1466

aberbotimue 10-22-2009 04:01 PM

Need to alter the text in code...
 
I see the method, but I am constructing some of the main parts of the rtf from within the code too.. if i understand this code, its printing the rtf, externaly to the code, so much harder to alter the file, and to print it..

but definatly a good fall back, if i can't crack this componant issue...

Jasser 10-22-2009 05:20 PM

You can manipulate the file using TStringlist and then save it back and then print it.

Code:

var
          oSL : TStringlist;
begin
          oSL := TStringlist.Create;
          oSL.LoadFromFile('C:\Thefile.rtf');

          //Do anything here with the file.

          oSL.SaveToFile('C:\Thefile.rtf');//To the same file or any new file.
          oSL.Free;


          //Then here try to print it.


aberbotimue 10-23-2009 05:15 PM

I hear what you are saying, and again as a fall back.. but if a few people are doing the tarnsaction at a time, I now need to manage multiple text files on the disk, where creating the rtf dynamicly, means its all managed within the web modual..

this route is more complex to print, uses files so have to manage names etc..

That all said, its getting too close to having to go another route, as this creating an rtf on the fly is turning out to be a mare - no one can help..


All times are GMT. The time now is 04:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.