TEdit and strings

heyy all,

this is my second post :D.
but hey i'm working on forms in C++ builder 6
and i'm stuck with this problem.
i made form that will display a map like a blueprint, and i got
doors that i can open and close :D:P, but now i need to put locks on the door, like a code and key(key is a textstring), the code is working fine, but when i work on the text it wouldn't work.
i already got:
sleutelslot.cpp/h with:
#include "Slot.h" //slot stands for lock
#include
using namespace std;

class SleutelSlot: public Slot sleutel stands for key
{
public:
SleutelSlot(string);
void Ontgrendel(string); //unlock
void Vergrendel(); //lock
bool isVergrendeld(); //REQ for status
private:
string sleutel; //the key
bool status; //status (locked/unlocked)
};

in the form i made:
string foo("bar");
slot2=new SleutelSlot(foo);
and when i want to read TEdit:
slot1->Ontgrendel(Edit1->Text.c_str());
but here isn't an string sent to Ontgrendel
how can i fix this?

TY for reacting

Comments

  • : heyy all,
    :
    : this is my second post :D.
    : but hey i'm working on forms in C++ builder 6
    : and i'm stuck with this problem.
    : i made form that will display a map like a blueprint, and i got
    : doors that i can open and close :D:P, but now i need to put locks on the door, like a code and key(key is a textstring), the code is working fine, but when i work on the text it wouldn't work.
    : i already got:
    : sleutelslot.cpp/h with:
    : #include "Slot.h" //slot stands for lock
    : #include
    : using namespace std;
    :
    : class SleutelSlot: public Slot sleutel stands for key
    : {
    : public:
    : SleutelSlot(string);
    : void Ontgrendel(string); //unlock
    : void Vergrendel(); //lock
    : bool isVergrendeld(); //REQ for status
    : private:
    : string sleutel; //the key
    : bool status; //status (locked/unlocked)
    : };
    :
    : in the form i made:
    : string foo("bar");
    : slot2=new SleutelSlot(foo);
    : and when i want to read TEdit:
    : slot1->Ontgrendel(Edit1->Text.c_str());
    : but here isn't an string sent to Ontgrendel
    : how can i fix this?
    :

    Hello ...NoiK,

    The contruction of your code seems perfect (except you are not const-correct, www.codepedia.com/1/CppConst).

    Therefore, I'd guess that either you did not couple an Event to sending the char* from TEdit to SleutelSlot. A good choice would be the OnEdit event of TEdit. Or I'd guess the edit area of the TEdit would be still empty.

    Hope to have helped you out,




    bilderbikkel

  • [b][red]This message was edited by ...NoiK at 2006-12-13 4:9:36[/red][/b][hr]
    [b][red]This message was edited by ...NoiK at 2006-12-13 3:52:47[/red][/b][hr]
    : : heyy all,
    : :
    : : this is my second post :D.
    : : but hey i'm working on forms in C++ builder 6
    : : and i'm stuck with this problem.
    : : i made form that will display a map like a blueprint, and i got
    : : doors that i can open and close :D:P, but now i need to put locks on the door, like a code and key(key is a textstring), the code is working fine, but when i work on the text it wouldn't work.
    : : i already got:
    : : sleutelslot.cpp/h with:
    : : #include "Slot.h" //slot stands for lock
    : : #include
    : : using namespace std;
    : :
    : : class SleutelSlot: public Slot sleutel stands for key
    : : {
    : : public:
    : : SleutelSlot(string);
    : : void Ontgrendel(string); //unlock
    : : void Vergrendel(); //lock
    : : bool isVergrendeld(); //REQ for status
    : : private:
    : : string sleutel; //the key
    : : bool status; //status (locked/unlocked)
    : : };
    : :
    : : in the form i made:
    : : string foo("bar");
    : : slot2=new SleutelSlot(foo);
    : : and when i want to read TEdit:
    : : slot1->Ontgrendel(Edit1->Text.c_str());
    : : but here isn't an string sent to Ontgrendel
    : : how can i fix this?
    : :
    :
    : Hello ...NoiK,
    :
    : The contruction of your code seems perfect (except you are not const-correct, www.codepedia.com/1/CppConst).
    :
    : Therefore, I'd guess that either you did not couple an Event to sending the char* from TEdit to SleutelSlot. A good choice would be the OnEdit event of TEdit. Or I'd guess the edit area of the TEdit would be still empty.
    :
    : Hope to have helped you out,
    :
    :
    :
    :
    : bilderbikkel
    :
    :
    hey bilderbikkel,
    thnx for the reply.
    this morning i got it working and te only things i changed was that i added:
    [code]#include
    using namespace std;[/code]
    to the base class "slot", the program compiles and runs now.
    the firstlock i made was a code lock, that worked before still works so that's not a problem. but the second lock i made,that contains the string not. and i doesn't look like the variables are sended through.
    i tried to use watches but the don't give result, as of the weren't used. but the must be used(process not accessible). maybe it's the way i make the watches.
    so i'm gonna look for a tutorial about watches.
    hope you got some ideas why it doesn't work. the things i last used were:
    same way of making the object.
    [code]void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)
    {
    if (Key == VK_RETURN)
    {
    Key = NULL;
    slot2->Ontgrendel(Edit2->Text.c_str());
    Edit2->Text="";
    }
    }
    void SleutelSlot::Ontgrendel(string sample)
    {
    if (sample==sleutel)
    {
    status=true;
    }
    }[/code]
    Thank you,

    and about posting here, do i need to quote every previous posts?
    or may i take text out because in previousepost it is also?
    thank you it's my first time on a messageboard like this

    THANKS,...NoiK




  • Hi ...noiK,

    : [code]#include
    : using namespace std;[/code]
    That adding this code had an influence is suspicious and perhaps undesired. In C++ Builder you already have a global scope AnsiString type and mixing it with a global scoped std::string probably is not what you want. I'd suggest -but perhaps it is not the problem at all- that you remove the 'using namespace std' (see also www.codepedia.com/1/CppUsing).

    : [code]void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)
    : {
    : if (Key == VK_RETURN)
    : {
    : Key = NULL;
    : slot2->Ontgrendel(Edit2->Text.c_str());
    : Edit2->Text="";
    : }
    : }
    : void SleutelSlot::Ontgrendel(string sample)
    : {
    : if (sample==sleutel)
    : {
    : status=true;
    : }
    : }[/code]

    This code looks fine, except when you are a bit picky.

    [code]
    : void SleutelSlot::Ontgrendel(const std::string& sample)
    [/code]

    So, I cannot help you anymore. No problem this is your first post, you did a great job (especially compared to the 'Can u do myy homewurck please' (spelling intended)).

    Groetjes en haudoe,

    bilderbikkel

  • hey

    well it was for my homework, but it was just a little thing and i already knew what i made, i only had a problem so was asking for a bit advice ;)
    on a subject were i knew the answer of but didn't knew it in code, but hey thnx, and i see i didn't had to translate the code according to your dutch greetings :P.

    but now i can go on to the next assignment, using lock in a list, well don't need to as anything now cause i haven't started yet ;)

    greetz(en bedankt),
    ...NoiK


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories