如何将colorbox1中的各条颜色添加到mainmenu1中并能够被执行? RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用ColorToString将颜色转为字符串作为菜单项的name然后执行时StringToColor将name转为color unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ColorGrd, ImgList, Menus, ADODB, Provider, DB, DBClient, ComCtrls, ToolWin;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } //两个过程的定义: procedure ButtonClick(Sender: TObject); procedure MenuClick(Sender:TObject); public { Public declarations } end;var Form1: TForm1;implementationvar ColorBox:TColorBox; MainMenu:TMainMenu; Colorlist,Coloritem:TMenuItem; Button:TButton; Panel:TPanel; Lab:TLabel; StatusBar:TStatusBar;{$R *.dfm}//新建一个工程、双击窗体、输入以下代码:procedure TForm1.FormCreate(Sender: TObject);begin Form1.Width:=330; Form1.Height:=280; Form1.Caption:='将ColorBox的颜色添加MainMenu'; Form1.Position:=poScreenCenter; StatusBar:=TStatusBar.Create(self); StatusBar.Parent:=form1; StatusBar.Panels.Add; StatusBar.Panels[0].Text:='中国软件研发联盟QQ群122058606 广州佬'; Button:=TButton.Create(self); Button.Parent:=form1; Button.Caption:='建立主菜单'; Button.Top:=Form1.Height div 2-24; Button.Left:=Form1.Width div 2 - Button.Width div 2; Button.OnClick:=ButtonClick;end;//增加以下两过程:procedure TForm1.ButtonClick(Sender: TObject);var i,r,g,b,x,y:integer; bmp:TBitmap; ImageList:TImageList; PRGB:pRGBTriple; mc:TColor;begin bmp:=TBitmap.Create; ImageList:=TImageList.Create(self); ColorBox:=TColorBox.Create(self); ColorBox.Parent:=form1; ColorBox.Left:=-300; MainMenu:=TMainMenu.Create(self); MainMenu.AutoHotkeys:=maManual; MainMenu.Images:=ImageList; Colorlist:=TMenuItem.Create(self); Form1.Menu:=MainMenu; Colorlist.Caption:='颜色选择'; Colorlist.Name:='Colorlist'; MainMenu.items.insert(MainMenu.items.count,Colorlist); for i:=0 to ColorBox.Items.Count-1 do begin Coloritem:=TMenuItem.Create(self); Coloritem.Caption:=ColorBox.Items.Strings[i]; Coloritem.Name:='N'+inttostr(i); Colorlist.Insert(Colorlist.Count,Coloritem); Colorlist.Items[Colorlist.Count-1].ImageIndex:=i; Colorlist.Items[Colorlist.Count-1].OnClick:=MenuClick; mc:=ColorBox.Colors[i]; if mc<0 then mc:=GetSysColor(mc and $000000FF); r:=GetRValue(mc); g:=GetGValue(mc); b:=GetBValue(mc); bmp.PixelFormat:=pf24bit; bmp.width:=16; bmp.height:=16; for y:=0 to bmp.Height-1 do begin pRGB:=bmp.ScanLine[Y]; for x:=0 to bmp.Width-1 do begin pRGB^.rgbtRed:=r; pRGB^.rgbtGreen:=g; pRGB^.rgbtBlue:=b; inc(pRGB); end; end; ImageList.Add(bmp,nil); end; bmp.Free; ColorBox.Free; Panel:=TPanel.Create(self); Panel.Visible:=false; Panel.BevelInner:=bvLowered; Panel.Parent:=form1; Panel.Height:=Button.Height; Panel.Width:=Button.Width; Panel.Top:=Button.Top; Panel.Left:=Button.Left; Lab:=TLabel.Create(self); Lab.Visible:=false; Lab.Parent:=form1; Lab.Left:=Panel.Left; Lab.Top:=Panel.Top-16; Lab.Caption:='选择的颜色:'; Button.Visible:=false;end;procedure TForm1.MenuClick(Sender:TObject);var mc:Tcolor;begin Lab.Visible:=true; Panel.Visible:=true; IdentToColor(TMenuItem(Sender).Caption,integer(mc)); if mc<0 then mc:=GetSysColor(mc and $000000FF); Panel.Color:=mc;end;end. 新建一个工程、双击窗体后,复制上述所有代码、覆盖你的unit1的内容,即可编译运行。 18 pthread_attr 181INT iRet=CCU_ERR;pthread_t hThreadId = 0;181_t attr;CHECK;181_init(&attr);iRet = 181_setstacksize(&attr, ulStackSize);if (IPC_FAIL_CODE == iRet) {21("Set thread stack fail, %s", 24);181_destroy(&attr);222;}iRet = pthread_create(&hThreadId, &attr, (VOID *(*)(VOID*))pfnFunc, (VOID *)pucArg); if (IPC_FAIL_CODE == iRet) {21("Creat thread fail, %s", 24);181_destroy(&attr);222;}*ulThreadId = (UINT32)hThreadId;181_destroy(&attr);221;19/* 我们认为合法的年是1970-2038 */if((iYear < 2038) && (iYear >= 1970)){return CCU_TRUE;}return CCU_FALSE;20INT32 iRet = -1; struct tm pstTime = {0}; time_t SecCount = 0;INT32 iTimeZone = 0;UINT8 aucBuf[4] = {0};CHECK; iRet = sscanf((CHAR*)pucStr, "%d:%d:%d-%d:%d:%d-%d", &(pstTime.tm_year), &(pstTime.tm_mon),&(pstTime.tm_mday), &(pstTime.tm_hour), &(pstTime.tm_min), &(pstTime.tm_sec), (int*)&iTimeZone);if(7 != iRet){222;} if((iTimeZone > 12)||(iTimeZone < -12)){ return 11;}/* 判断年是不是合法的 */if(CCU_TRUE != IsYearLegal(pstTime.tm_year)){return 11;}if (CCU_OK != CheckTime(&pstTime)){return 11;}pstTime.tm_year -= 1900;pstTime.tm_mon -= 1; SecCount = mktime(&pstTime);if (-1 == SecCount){222;}iRet = ADA_SetRTCTime((unsigned int)SecCount, iTimeZone);if(-1 == iRet){222;}aucBuf[0] = (UINT8)iTimeZone + 48; /* itoa */return CFG_SetTimeZone(aucBuf);21 struct timeval tv 214 ucTimeZone 215214;int iRet = -1;if((iTimeZone > 12) || (iTimeZone < -12)){return 11;}/* 时间认定是设置本时区的时间 不再和时区绑定 */tv.tv_sec = (long)ulSecCount; tv.tv_usec = 0;/* 按照惯例 将其tz设置为0 */ iRet = settimeofday(&tv, NULL);if (0 != iRet){21("errno is %s", 24);56;} /* 将其写入硬件RTC */iRet = system("hwclock -w");if (CCU_OK == iRet){g_iTimeZone = iTimeZone;} 56; #if __CCU_305__int IsTimeParaIllegal(unsigned char ucflag, unsigned char 215, unsigned char ucTimeMinute){if ((ucflag != 0x2B) && (ucflag != 0x2D)){222;}if (215 > 11){ 222;}if (ucTimeMinute > 59){222;}221;}int ADA_SetUTCTime(unsigned int ulSecCount, unsigned char ucflag, unsigned char 215, unsigned char ucTimeMinute){214;int iRet = -1;iRet = IsTimeParaIllegal(ucflag, 215, ucTimeMinute);CHECK_RET1(iRet, iRet);tv.tv_sec = (long)ulSecCount; /*减去中国时区*/tv.tv_usec = 0; /* 按照惯例 将其tz设置为0 */ iRet = settimeofday(&tv, NULL);if (0 != iRet){printf("errno is %s", 24);56;}/* 将其写入硬件RTC */iRet = system("hwclock -w");if (CCU_OK == iRet){g_215 = 215;g_ucTimeFlag = ucflag;g_ucTimeMin = ucTimeMinute;}56;}#endif22 pthread_mutexattr 221 CHECK_RET_OK_RN(iRet, iRet) 222221_t attr; INT32 iRet = -1;CHECKPARA(pmutex); iRet = 221_init(&attr); 222;/* 支持递归函数 */iRet = 221_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);222; iRet = 282init(pmutex,&attr);222;iRet = 221_destroy(&attr); 222;221;23CHECK;return (INT32)BSP_GetBoardOnLineStatus((UINT8)i, pucState);24UINT32 ulRet = CCU_ERR;UINT16 ucGpioNum = 0;ucGpioNum = ALARM_CARD_IO_START + ucSlotId * 17 + ucIoNum + 8; ulRet = ADP_GPIO_Write(ucGpioNum, (UINT8)enState);return (INT32)ulRet;25UINT32 ulRet = CCU_ERR;UINT8 ucValue = 0; UINT8 ucOffSet = 0x23; /* 控制电子门锁供电的寄存器偏移地址是0x23,bit4 */ulRet = ADP_CPLD_Read(ucOffSet, 1, &ucValue);222;if ( IO_SWITCH_OFF == enState ){ucValue &= ~(1 << 4); }else{ucValue |= 1 << 4;}ulRet = ADP_CPLD_Write(ucOffSet, 1, &ucValue);return (INT32)ulRet;26 CHECK; return(BSP_GetBoardType(ucSlotId, pucCardType));27return 0;28 testDebug() 281 pthread_mutex_ 282INT32 iRet = 0; CHECK;iRet = 282lock(pmutex);if (57){printf("\r\n the 1iRet is %d the err is %s\n", (int)iRet, 24);281; } 56;29 INT32 iRet = 0;CHECK;iRet = 282unlock(pmutex);if (57){printf("\r\n 2the iRet is %d err no is %d the err is %s\n", (int)iRet, errno, 24);281;}56;30214;struct timezone tz;CHECK if (0 != gettimeofday(&tv,&tz)){222;}*plSec = tv.tv_sec;*plUsec = tv.tv_usec;221; delphi 在多线程情况下不会报错 小问题--loadfromfile 鼠标在窗体上的 移入 和 移出 事件 这样的错误,有人知道是怎么一回事吗? 有誰可以提供f1book的帮助或者例子阿? 对表操作的语句中的TField能否使用变量? 求助,CONTROL[I].CLASSTYPE問題 找一个能看WORD2000文档的控件 如何在程序中定时? 有关外观 【求助】关于数学形态学delphi实现的问题 一个简单的Delphi7小设置问题?
然后执行时StringToColor将name转为color
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ColorGrd, ImgList, Menus, ADODB, Provider,
DB, DBClient, ComCtrls, ToolWin;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
//两个过程的定义:
procedure ButtonClick(Sender: TObject);
procedure MenuClick(Sender:TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementationvar ColorBox:TColorBox;
MainMenu:TMainMenu;
Colorlist,Coloritem:TMenuItem;
Button:TButton;
Panel:TPanel;
Lab:TLabel;
StatusBar:TStatusBar;{$R *.dfm}//新建一个工程、双击窗体、输入以下代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Width:=330;
Form1.Height:=280;
Form1.Caption:='将ColorBox的颜色添加MainMenu';
Form1.Position:=poScreenCenter;
StatusBar:=TStatusBar.Create(self);
StatusBar.Parent:=form1;
StatusBar.Panels.Add;
StatusBar.Panels[0].Text:='中国软件研发联盟QQ群122058606 广州佬';
Button:=TButton.Create(self);
Button.Parent:=form1;
Button.Caption:='建立主菜单';
Button.Top:=Form1.Height div 2-24;
Button.Left:=Form1.Width div 2 - Button.Width div 2;
Button.OnClick:=ButtonClick;
end;//增加以下两过程:
procedure TForm1.ButtonClick(Sender: TObject);
var i,r,g,b,x,y:integer;
bmp:TBitmap;
ImageList:TImageList;
PRGB:pRGBTriple;
mc:TColor;
begin
bmp:=TBitmap.Create;
ImageList:=TImageList.Create(self);
ColorBox:=TColorBox.Create(self);
ColorBox.Parent:=form1;
ColorBox.Left:=-300;
MainMenu:=TMainMenu.Create(self);
MainMenu.AutoHotkeys:=maManual;
MainMenu.Images:=ImageList;
Colorlist:=TMenuItem.Create(self);
Form1.Menu:=MainMenu;
Colorlist.Caption:='颜色选择';
Colorlist.Name:='Colorlist';
MainMenu.items.insert(MainMenu.items.count,Colorlist);
for i:=0 to ColorBox.Items.Count-1 do
begin
Coloritem:=TMenuItem.Create(self);
Coloritem.Caption:=ColorBox.Items.Strings[i];
Coloritem.Name:='N'+inttostr(i);
Colorlist.Insert(Colorlist.Count,Coloritem);
Colorlist.Items[Colorlist.Count-1].ImageIndex:=i;
Colorlist.Items[Colorlist.Count-1].OnClick:=MenuClick;
mc:=ColorBox.Colors[i];
if mc<0 then mc:=GetSysColor(mc and $000000FF);
r:=GetRValue(mc);
g:=GetGValue(mc);
b:=GetBValue(mc);
bmp.PixelFormat:=pf24bit;
bmp.width:=16;
bmp.height:=16;
for y:=0 to bmp.Height-1 do
begin
pRGB:=bmp.ScanLine[Y];
for x:=0 to bmp.Width-1 do
begin
pRGB^.rgbtRed:=r;
pRGB^.rgbtGreen:=g;
pRGB^.rgbtBlue:=b;
inc(pRGB);
end;
end;
ImageList.Add(bmp,nil);
end;
bmp.Free;
ColorBox.Free;
Panel:=TPanel.Create(self);
Panel.Visible:=false;
Panel.BevelInner:=bvLowered;
Panel.Parent:=form1;
Panel.Height:=Button.Height;
Panel.Width:=Button.Width;
Panel.Top:=Button.Top;
Panel.Left:=Button.Left;
Lab:=TLabel.Create(self);
Lab.Visible:=false;
Lab.Parent:=form1;
Lab.Left:=Panel.Left;
Lab.Top:=Panel.Top-16;
Lab.Caption:='选择的颜色:';
Button.Visible:=false;
end;procedure TForm1.MenuClick(Sender:TObject);
var mc:Tcolor;
begin
Lab.Visible:=true;
Panel.Visible:=true;
IdentToColor(TMenuItem(Sender).Caption,integer(mc));
if mc<0 then mc:=GetSysColor(mc and $000000FF);
Panel.Color:=mc;
end;end.
INT iRet=CCU_ERR;pthread_t hThreadId = 0;181_t attr;CHECK;181_init(&attr);
iRet = 181_setstacksize(&attr, ulStackSize);if (IPC_FAIL_CODE == iRet)
{21("Set thread stack fail, %s", 24);181_destroy(&attr);222;}
iRet = pthread_create(&hThreadId, &attr, (VOID *(*)(VOID*))pfnFunc, (VOID *)pucArg);
if (IPC_FAIL_CODE == iRet)
{21("Creat thread fail, %s", 24);181_destroy(&attr);222;}
*ulThreadId = (UINT32)hThreadId;181_destroy(&attr);221;
19/* 我们认为合法的年是1970-2038 */
if((iYear < 2038) && (iYear >= 1970)){return CCU_TRUE;}return CCU_FALSE;
20
INT32 iRet = -1; struct tm pstTime = {0}; time_t SecCount = 0;
INT32 iTimeZone = 0;UINT8 aucBuf[4] = {0};CHECK;
iRet = sscanf((CHAR*)pucStr, "%d:%d:%d-%d:%d:%d-%d", &(pstTime.tm_year), &(pstTime.tm_mon)
,&(pstTime.tm_mday), &(pstTime.tm_hour), &(pstTime.tm_min), &(pstTime.tm_sec), (int*)&iTimeZone);
if(7 != iRet){222;}
if((iTimeZone > 12)||(iTimeZone < -12)){ return 11;}/* 判断年是不是合法的 */
if(CCU_TRUE != IsYearLegal(pstTime.tm_year)){return 11;}
if (CCU_OK != CheckTime(&pstTime)){return 11;}
pstTime.tm_year -= 1900;pstTime.tm_mon -= 1;
SecCount = mktime(&pstTime);if (-1 == SecCount){222;}
iRet = ADA_SetRTCTime((unsigned int)SecCount, iTimeZone);if(-1 == iRet){222;}
aucBuf[0] = (UINT8)iTimeZone + 48; /* itoa */return CFG_SetTimeZone(aucBuf);
21 struct timeval tv 214 ucTimeZone 215
214;int iRet = -1;if((iTimeZone > 12) || (iTimeZone < -12)){return 11;}
/* 时间认定是设置本时区的时间 不再和时区绑定 */
tv.tv_sec = (long)ulSecCount; tv.tv_usec = 0;
/* 按照惯例 将其tz设置为0 */ iRet = settimeofday(&tv, NULL);
if (0 != iRet){21("errno is %s", 24);56;}
/* 将其写入硬件RTC */iRet = system("hwclock -w");
if (CCU_OK == iRet){g_iTimeZone = iTimeZone;} 56;
int IsTimeParaIllegal(unsigned char ucflag, unsigned char 215, unsigned char ucTimeMinute)
{if ((ucflag != 0x2B) && (ucflag != 0x2D)){222;}
if (215 > 11){ 222;}if (ucTimeMinute > 59){222;}221;}
int ADA_SetUTCTime(unsigned int ulSecCount, unsigned char ucflag,
unsigned char 215, unsigned char ucTimeMinute){214;int iRet = -1;
iRet = IsTimeParaIllegal(ucflag, 215, ucTimeMinute);CHECK_RET1(iRet, iRet);
tv.tv_sec = (long)ulSecCount; /*减去中国时区*/tv.tv_usec = 0;
/* 按照惯例 将其tz设置为0 */ iRet = settimeofday(&tv, NULL);
if (0 != iRet){printf("errno is %s", 24);56;}
/* 将其写入硬件RTC */iRet = system("hwclock -w");if (CCU_OK == iRet)
{g_215 = 215;g_ucTimeFlag = ucflag;g_ucTimeMin = ucTimeMinute;}56;}#endif
22 pthread_mutexattr 221 CHECK_RET_OK_RN(iRet, iRet) 222
221_t attr; INT32 iRet = -1;CHECKPARA(pmutex);
iRet = 221_init(&attr); 222;
/* 支持递归函数 */
iRet = 221_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);222;
iRet = 282init(pmutex,&attr);222;iRet = 221_destroy(&attr); 222;221;
23
CHECK;return (INT32)BSP_GetBoardOnLineStatus((UINT8)i, pucState);
24UINT32 ulRet = CCU_ERR;UINT16 ucGpioNum = 0;
ucGpioNum = ALARM_CARD_IO_START + ucSlotId * 17 + ucIoNum + 8;
ulRet = ADP_GPIO_Write(ucGpioNum, (UINT8)enState);return (INT32)ulRet;
25
UINT32 ulRet = CCU_ERR;UINT8 ucValue = 0;
UINT8 ucOffSet = 0x23; /* 控制电子门锁供电的寄存器偏移地址是0x23,bit4 */
ulRet = ADP_CPLD_Read(ucOffSet, 1, &ucValue);
222;if ( IO_SWITCH_OFF == enState )
{ucValue &= ~(1 << 4); }else{ucValue |= 1 << 4;}
ulRet = ADP_CPLD_Write(ucOffSet, 1, &ucValue);
return (INT32)ulRet;
26
CHECK; return(BSP_GetBoardType(ucSlotId, pucCardType));
27
return 0;
28 testDebug() 281 pthread_mutex_ 282
INT32 iRet = 0; CHECK;iRet = 282lock(pmutex);if (57)
{printf("\r\n the 1iRet is %d the err is %s\n", (int)iRet, 24);281; } 56;
29 INT32 iRet = 0;CHECK;iRet = 282unlock(pmutex);
if (57){printf("\r\n 2the iRet is %d err no is %d the err is %s\n", (int)iRet, errno, 24);281;}56;
30
214;struct timezone tz;
CHECK if (0 != gettimeofday(&tv,&tz))
{222;}*plSec = tv.tv_sec;*plUsec = tv.tv_usec;221;