Topic: Script help please

Could somebody correct the following script please

procedure Form1_OnShow (Sender: string; Action: string);
begin
if Form1.cbMainMethStrategy.dbItemID = '' then
   begin
   Form1.btnStrategyDetails.Enabled := False;
   end else Form1.btnStrategyDetails.Enabled := True;
end;

cbMainMethStrategy is a comboBox

Adam
God... please help me become the person my dog thinks I am.

Re: Script help please

Hello ad1408

procedure Form1_OnShow (Sender: string; Action: string);
begin
    if Form1.cbMainMethStrategy.dbItemID = -1
       then
               begin
                         Form1.btnStrategyDetails.Enabled  := False
        else
                          Form1.btnStrategyDetails.Enabled := True;
               end;
end;

JB

Re: Script help please

Hi JB,

Thanks a lot but it didn't work at my end.

Adam
God... please help me become the person my dog thinks I am.

Re: Script help please

try this

procedure Form1_OnShow (Sender: string; Action: string);
begin
    if Form1.cbMainMethStrategy.dbItemID = -1 then Form1.btnStrategyDetails.Enabled := False else Form1.btnStrategyDetails.Enabled := True;
end;
Dmitry.

Re: Script help please

Hello ad1408, Hello Dmitry

I was so obsessed with the begin-end parity that I put it everywhere !

JB

Re: Script help please

Hi Dmitry,

Thank you very much...... it works.

Adam
God... please help me become the person my dog thinks I am.

7 (edited by sdhale29 2020-03-17 22:55:47)

Re: Script help please

Dmitry,


if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;

Enabled and Disabled is not working with DBFiles using combobox.dbItemID = -1

i have even set the combobox to -1 on show

procedure add_file_OnShow (Sender: TObject; Action: string);
begin
add_file.ComboBox2.dbItemID := -1;
if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;
end;

Im not sure why

I am on 6.3 i haven't tried to go back to an earlier version.

Sonny.

Re: Script help please

I checked, it works for me. Please attach your project (zip file without exe and dll), I'll test it.

Dmitry.

Re: Script help please

DriveSoft wrote:

I checked, it works for me. Please attach your project (zip file without exe and dll), I'll test it.

Here you go Sir

Post's attachments

Attachment icon Test.zip 6.22 kb, 285 downloads since 2020-03-18 

Sonny.

Re: Script help please

just change this line

if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := True else add_file.DBFile1.Enabled := False;

to

if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;
Dmitry.

11 (edited by sdhale29 2020-03-18 16:16:49)

Re: Script help please

DriveSoft wrote:

just change this line

if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := True else add_file.DBFile1.Enabled := False;

to

if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;

Dmitry,

Thank you

I did change it.  Now it stays disabled even after selection.
I attached a zip with it changed.

Post's attachments

Attachment icon Test.zip 6.23 kb, 287 downloads since 2020-03-18 

Sonny.

Re: Script help please

You need to place your IF statement inside the OnChange event of the combobox. See attached revision.

Post's attachments

Attachment icon sdhale29 test revised.zip 338.83 kb, 301 downloads since 2020-03-18 

Re: Script help please

ehwagner wrote:

You need to place your IF statement inside the OnChange event of the combobox. See attached revision.

Thank you so much, I tried so many things and researched for hours before asking.  I thought that I had tried that too.  I am learning a lot from you guys.  Again thanks from Texas!!!!!

Sonny.

Re: Script help please

I know the feeling. But don't stress yourself out for hours. Just ask here and someone will get you an answer. There's a lot of good resources on this forum. Happy developing!

Re: Script help please

Dmitry,

I had tried that, this is why it  was so confusing.  You have to have it on both OnFormShow event and on the OnChange event or it will not work.  It must be in both places.


Just OnShow will not allow selection of the DBFile box at all.


Just OnChange will allow you select it no matter what.


Using both together gets me the result that I need.

So it must be like this to work

procedure add_file_ComboBox2_OnChange (Sender: TObject);

begin
    if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;
end;

procedure add_file_OnShow (Sender: TObject; Action: string);
begin
    if add_file.ComboBox2.dbItemID = -1 then add_file.DBFile1.Enabled := False else add_file.DBFile1.Enabled := True;
end;

Thanks

Thanks to you too ehwagner.  The research really helps, sometimes I find stuff by accident that way.

Sonny.

Re: Script help please

I would recommend doing what I did, especially if one is new to MVD, and that is create a database (in MVD of course) of code snippets and examples. I use it as a kind of help system for MVD. I refer to mine almost daily. When I first came to MVD I was using the forum for most of my assistance, but I found out early on that it can be laborious trying to find what you are looking for, even when using the search tool. Many times there are solutions in topics where the topic title has nothing to do with the solution itself or somebody may post another subject under a topic in question. Don't get me wrong, the forum is an invaluable tool for assistance. I have learned most everything from the forum and it provides the basis for updating my code snippet database. I download most every project attachment and if there is something in the project that is new or something I did not know, then I insert the code snippet in my database for future referencing. That way I don't have to go back to the forum to try and find it a year later or whenever.

Re: Script help please

Hello sdhale29, hello ehwagner

I do the same.
As soon as I signed up for the MVD forum, I used a note manager in which I save all the reusable code snippets (with some arrangements) in my projects.
All this with categories in a Treeview (dates, grids, colors, scripts ...).
As ehwagner says, the forum is an inexhaustible source of solutions to practically all problems.
Besides, we can even create this note manager with MVD; there are all the necessary tools (components): Treeview, Memo, password an do one.It could even be a challenge.
MVD is a great tool, the forum is an essential source for solving problems and the MVD community has some good sizes ready to help beginners.

Welcome to the newbies, you are not alone inside MVD !

JB