Hi,
I am trying to use GuiEdit to save data to static variables for each symbol. However I am not able to figure out where am I doing wrong in below code. I checked using TRACE and found that its storing data in static vars but as soon as I change symbol couple of times the data is no longer available! Not getting how the data is getting reset ! Any suggestion would be helpful.
PS: I already tried using the event functionality (such as using notifyEditChange ) but that's crashing my Amibroker GUI dashboard as it continues to refresh in an infinite loop. I read a similar topic in the forum ( https://forum.amibroker.com/t/guiedit-guibutton-puzzling-errors-when-clicked-several-times/17218/3 ) where it was hinted that it might be due to individual's machine configuration(BTW , My Amibroker version is 6.31.0 32 bit and using Windows 10 OS). So dropped that method of implementation as of now. Instead I am trying to using a GuiEdit/GuiButton Combo to save data in symbol specific staticvars and display the staticvar data on the GuiEdit Component whenever required.
My trimmed sample Code is as below -
_SECTION_BEGIN("Procedure");
global id_LotSize; id_LotSize = 100;
global id_SaveRefresh; id_SaveRefresh = 101;
global SymbolChanged;
global Trachine_Svar_Name_LotSize; Trachine_Svar_Name_LotSize = "Stk_Svar_" + Name() + "_LotSize";
global Trachine_Svar_Value_LotSize; Trachine_Svar_Value_LotSize = StaticVarGetText(Trachine_Svar_Name_LotSize);
if(Trachine_Svar_Value_LotSize == "") { StaticVarSetText(Trachine_Svar_Name_LotSize,"1",True); }
function HasSymbolChanged()
{
RC = False;
CurrentSymbol = Name();
PreviousSymbol = StaticVarGetText( "Svar_PreviousSymbol" );
if(CurrentSymbol != PreviousSymbol)
{
RC = True;
StaticVarSetText("Svar_PreviousSymbol", Name());
}
return RC;
}
procedure CreateLabel(InputText, FontSize, TextColor, Column_X_Cor, Row_Y_Cor)
{
GfxSetBkMode( 1 );
GfxSelectFont("Aerial", FontSize, 800 ,False,False);
GfxSetTextColor(TextColor);
GfxTextOut(InputText, Column_X_Cor, Row_Y_Cor);
}
procedure CreateTextBox(TbxId,TbxStaticVar,Column_X_Cor,Row_Y_Cor, TbxLength, TbxWidth, FontSize,SymChanged)
{
GuiSetFont("Aerial",FontSize);
rc = GuiEdit( TbxId, Column_X_Cor, Row_Y_Cor, TbxLength, TbxWidth, 0);
//GuiEdit( TbxId, Column_X_Cor, Row_Y_Cor, TbxLength, TbxWidth, notifyKillFocus); // Not Working .. Maybe due to System Config
//GuiEdit( TbxId, Column_X_Cor, Row_Y_Cor, TbxLength, TbxWidth, notifyEditChange);// Not Working .. InfiniteRefresh.. Maybe due to System Config
//SymChanged = HasSymbolChanged();
if(rc == guiNew OR SymChanged == True)
{
_TRACE("SymbolChanged = " + SymChanged + "StaticVar = " + TbxStaticVar);
GuiSetText(StaticVarGetText(TbxStaticVar),TbxId);
}
}
procedure HandleEvents()
{
for ( n = 0; id = GuiGetEvent( n, 0 ); n++ ) // get the id of the event
{
code = GuiGetEvent( n, 1 );
switch ( id )
{
case id_SaveRefresh:
_TRACE("LSz = " + GuiGetValue(id_LotSize));
StaticVarSetText(Trachine_Svar_Name_LotSize,GuiGetText(id_LotSize),True);
break;
}
}
}
SymbolChanged = HasSymbolChanged();
CreateLabel("LotSize" ,10,colorWhite,10 , 50);
CreateTextBox(id_LotSize, Trachine_Svar_Name_LotSize, 110 , 50, 80, 30, 10,SymbolChanged);
GuiButton("SAVE / REFRESH",id_SaveRefresh,10, 100, 200,45, notifyClicked);
_SECTION_END();
Thanks,
Nandy