Design-time means
I've created simle report where one field is displayed. I need to change font(bold or not bold) for this field depending on other fields.
Is it possible at design-time ? Or I need to create objects dynamically at run-time ?
Is it possible at design-time ? Or I need to create objects dynamically at run-time ?
Comments
to change in runtime depending on an expression
you can either write code in obp event of band or memo
or use conditional highlight prop to add expression and set colors or font props.
Thanks. I tried following solution but it didn't work(no values actually displayed in report):
TfrMemoView * m;
report->LoadFromFile("e:\\4\test.frf");
report->PrepareReport();
TfrPage * page = new TfrPage(100,200,100,100,poLandscape);
report->EMFPages->Add(page);
report->EMFPages->ObjectsToPage(0);
m = new TfrMemoView;
m->SetBounds(220,120,200,16);
m->FillColor = clRed;
m->Font = this->Font;
m->Name="MemeoTest";
m->Script->Add("[FORMATDATETIME('dd mmmm yyyy',[DATE])]");
report->EMFPages->Pages[0]->Page->Objects->Add(m);
report->EMFPages->PageToObjects(0);
report->ShowPreparedReport();
What are you actually trying to do
add a memo to a prepared report's emfpage(s) or add a memo to a report's designpage from external appcode?
You know. I need the simpliest way to resolve the problem: change font of memo at run-time. So please, help me with the code I wrote.
however if you want to modify objects from external code you must get syntax correct and in properplaces.
ie code to load report
use findobject method to find the object on design page
code to modify object
code to show report.
here is some sample delphi code to concantenate 2 reports into 1
and add a memo to each emfpage with specific text and font properties.
you will have to translate it to suit cbuilder.
procedure TForm1.Button5Click(Sender: TObject);
var
i: integer;
m : TfrMemoView;
mystring : string;
begin
frReport1.LoadFromFile(WPath + '1.frf');
frReport2.LoadFromFile(WPath + '3.frf');
frReport1.PrepareReport;
frReport2.PrepareReport;
frReport1.EMFPages.AddFrom(frReport2);
for i := 0 to frreport1.EMFPages.Count -1 do
begin
frReport1.EMFPages.ObjectsToPage(i);
m:=TfrMemoView.Create;
m.SetBounds(15,15,200,16);// create memo(l,t,w,h)in pixels
m.FillColor := clYellow;
mystring := 'Page '+inttostr(i+1)+' of '+inttostr(frreport1.EMFPages.Count)+ ' Pages';
m.Memo.Add(''+ mystring +'');
m.Name:='pageMemo';
m.prop:= 'Courier New';
m.prop := 8; // set font size
m.Prop := 6; // set memo's font style. value is sum of frstyle constants
// bold 2,ital 1, underline 4 strikeout 8
m.Prop := clBlack; // any delphi color constant
frreport1.EMFPages.Pages.Page.Objects.Add(m);
frReport1.EMFPages.PageToObjects(i);
end;
frreport1.showpreparedreport;
end;
Also watch your apostrophes
in most cases the sting value passed in needs extra to make up for the ide stripping.
the bit of code where you are trying to add something to the memos script is useless, it wont display anything. The script of a memo is the code of it's onbeforeprint event.
Thanks a lot.
I wrote the following code to display current date/time on the memo,but nothing was displayed.Do I use correct property('Script') and syntax ?
m->Script->Add("[FORMATDATETIME('dd mmmm yyyy',[DATE])]");
this is the way it would appear in the memo of the memoview(textobject)
in a design window, if you built the contents using the expression builder.
[FORMATDATETIME('dd mmmm yyyy',[DATE])]
since the ide strips the inner quotes when encountered it is easier to build the string in a variable then use the variable in the memoview's memo.add() method.
much like building a filterstring for a table or query.
from example this is where we added the value of mystring to the memoview's
memo.
m.Memo.Add(' '+ mystring +' ');
Sorry ... it doesn't work.
When I write: m->Memo->Add("[DATE]") it displays [DATE] as text, not current date value.
you'll eventually get it right.
you should see [Date] including brackets in the memo and when report is run the date will be subed for the the variable.
I tried single and double apostrophes. But it still displays [DATE] or '[DATE]' or something like this. Instead I need date value. In design-time everything is OK, but in run-time not
m.memo.add (FORMATDATETIME('dd/mm/yyyy',DATE));
if adding to a memo on design page which will then be processed you would add the expression
'[formatdatetime('+''''+'dd/mm/yyyy'+''''+',[DATE])]'