标签:
richview中的行高改变有点特别。必须在AfterData 事件执行的时候才能修改;
也就是说,如果简单的放一个按钮,去发送消息给richView->RichEdit ,然后调用frxReport1->ShowReport 是没有用的
正确的做法如下
下面是实现的代码
头文件
//--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include "frxClass.hpp" #include "frxDBSet.hpp" #include "frxPreview.hpp" #include <ADODB.hpp> #include <DB.hpp> #include "frxRich.hpp" //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TfrxReport *frxReport1; TfrxPreview *frxPreview1; TfrxDBDataset *frxDBDataset1; TADOConnection *ADOConnection1; TADOQuery *ADOQuery1; TButton *Button1; TfrxRichObject *frxRichObject1; TEdit *Edit1; TEdit *Edit2; TLabel *Label1; TLabel *Label2; void __fastcall FormCreate(TObject *Sender); Variant __fastcall frxReport1UserFunction(const AnsiString MethodName, Variant &Params); void __fastcall frxReport1EndDoc(TObject *Sender); void __fastcall Button1Click(TObject *Sender); private: // User declarations bool d_flag; public: // User declarations __fastcall TForm1(TComponent* Owner); void TForm1::SetLineSpace(AnsiString name); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "frxClass" #pragma link "frxDBSet" #pragma link "frxPreview" #pragma link "frxRich" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { d_flag = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { ADOQuery1->Open(); //add event notify function frxReport1->AddFunction("void SetLineSpace(name:String)", "SetLineSpace","change the linspace"); //add script for event handle frxReport1->ScriptLanguage = "C++Script"; frxReport1->ScriptText->Clear(); frxReport1->ScriptText->Add( "void richOnAfterData(TfrxComponent sender)" "{" " SetLineSpace(Sender.Name); " "}" ); //don‘t forget it frxReport1->ScriptText->Add("{}"); //set the event handle for richview‘s onAfterData TfrxRichView* rich = dynamic_cast<TfrxRichView*>( frxReport1->FindObject("Rich1")); rich->OnAfterData = "richOnAfterData"; } //--------------------------------------------------------------------------- void TForm1::SetLineSpace(AnsiString name) { TfrxRichView* rich = (TfrxRichView*)frxReport1->FindObject(name); rich->RichEdit->SelectAll(); PARAFORMAT2 Para; Para.cbSize = sizeof(Para); Para.dwMask = PFM_LINESPACING; Para.bLineSpacingRule = 4; Para.dyLineSpacing = Edit1->Text.ToIntDef(200); SendMessage(rich->RichEdit->Handle, EM_SETPARAFORMAT, 0, LPARAM(&Para)); rich->RichEdit->SelAttributes->Size = Edit2->Text.ToIntDef(20); } Variant __fastcall TForm1::frxReport1UserFunction( const AnsiString MethodName, Variant &Params) { if (MethodName.UpperCase() == AnsiString("SetLineSpace").UpperCase()) { SetLineSpace(Params.GetElement(0)); } } //--------------------------------------------------------------------------- void __fastcall TForm1::frxReport1EndDoc(TObject *Sender) { d_flag = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { //if click quickly ,the d_flag‘ll protect the thread synchrolized //otherwise your may get an error if (d_flag) { frxReport1->ShowReport(); d_flag = false; } } //---------------------------------------------------------------------------
实现的效果
此时文字重叠了
fastreport 如何 设置 richview 的 行高
标签:
原文地址:http://www.cnblogs.com/songr/p/5638234.html