一直想将BootStrap与Intraweb在CB下结合,今天尝试了一下,遇到一些问题,基本解决了。 粗粗的记录一下。
=========================================================================================
一、 安装
安装环境: win10专业版+RAD Studio XE10.1 update2 + IntraWeb14.1.10
1. 解压缩IWBootstrapFramework-master.rar
2. 打开工程dclIWBootstrapD101.dproj,
3. 更改工程选项 Output-C/C++ 为Generate all C++Builder files (including package libs)
4. 编译会报错,相当的莫名其妙, dclIWBootstrapD101.dpk文件会被修改, require段前多了一个r , contains段前多了一个o, 尾部的end. 变为了d.
改回来。 编译通过,安装,这样delphi和CB下就都有了。
5. 添加IWBS路径
二、 初步测试
1、在CB下新建一个Intraweb工程, 添加一个IWBSLabel控件, 编译报错,
[bcc32 Error] IWBSCustomControl.hpp(147): E2303 Type name expected,
__property OnHTMLtag; 对应的属性没有, 暂时屏蔽。(不知如何解决,请知道的朋友指点)
2. 在Dephi下新建一个Intraweb工程, 添加一个IWBS系列的控件, 可以正常编译运行, 但是添加控件的OnHTMLTag事件不成功!
三、 初步改造Dephi版IWBsDemo为CB版
1. 将Unit2的所有控件拷贝到 CB的Form上, 运行报错
2 . 改造ServerController如下,运行成功!(输出路径也到自带demo的bin下)
// *****************************************************************************
// with this global hooks you can apply a third party plugin to any component
// where for example we apply the excelent https://silviomoreto.github.io/bootstrap-select/
void MyRenderAsync(TComponent* AControl, const String AHTMLName, String AInputSelector)
{
TIWBSSelect *p;
if(p = dynamic_cast<TIWBSSelect *>(AControl))
{
WebApplication->CallBackResponse->AddJavaScriptToExecute("$(\"#"+AHTMLName+"\").selectpicker(\"refresh\");");
}
}
void MyBeforeRender(TComponent* AControl)
{
TIWBSSelect *p;
if(p = dynamic_cast<TIWBSSelect *>(AControl))
{
p->Css = "selectpicker";
}
}
//---------------------------------------------------------------------------
__fastcall TIWServerController::TIWServerController(TComponent* Owner)
: TIWServerControllerBase(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TIWServerController::IWServerControllerBaseNewSession(
TIWApplication *ASession)
{
ASession->Data = new TIWUserSession(NULL, ASession);
}
//---------------------------------------------------------------------------
void setServerController() {
TIWServerController::SetServerControllerClass();
}
TIWServerController* IWServerController()
{
return (TIWServerController*)gServerController;
}
#pragma startup setServerController
void __fastcall TIWServerController::IWServerControllerBaseConfig(TObject *Sender)
{
// This framework requires to disable IW embeded JQuery
JavaScriptOptions->RenderjQuery = False;
// here we can change IWBootstrap library files location to for example public cdns,
// ATTENTION!!!, this can't be done after this event because global variables are not thread safe
#ifdef CDNS
IWBSLibSetCDNS;
// we add a third party plugin to manage selects (https://silviomoreto.github.io/bootstrap-select)
#ifdef BOOTSTRAPSELECT
IWBSAddGlobalLinkFile('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.5/css/bootstrap-select.css');
IWBSAddGlobalLinkFile('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.7.5/js/bootstrap-select.js');
#endif
// custom css for this demo
IWBSAddGlobalLinkFile("https://cdn.rawgit.com/kattunga/IWBootstrapFramework/v1.5/demo/bin/wwwroot/iwbsdemo.css");
#else
// we add a third party plugin to manage selects
#ifdef BOOTSTRAPSELECT
IWBSAddGlobalLinkFile('/<iwbspath>/select/dist/css/bootstrap-select.min.css');
IWBSAddGlobalLinkFile('/<iwbspath>/select/dist/js/bootstrap-select.min.js');
#endif
// custom css for this demo
IWBSAddGlobalLinkFile("/iwbsdemo.css");
#endif
// I set the cache to a local directory, this is only to see how many temporary files are created
CacheDir = ExtractFilePath(ParamStr(0))+"temp";
}
void myInitial()
{
TIWServerController::SetServerControllerClass();
// set global events
#ifdef BOOTSTRAPSELECT
gIWBSOnRenderAsync = MyRenderAsync;
gIWBSOnBeforeRender = MyBeforeRender;
#endif
}
#pragma startup myInitial