How to use Memo1 in a function
Feb 17, 2009 at 9:11pm UTC
Hi everyone!
I'm trying to use Memo1 (as an text output on a Form) in a function. But it won't work. I get this Error:[C++ Error] Unit1.cpp(43): E2451 Undefined symbol 'Memo1'
Obviously I have to define "Memo1" in this function but I don't know how.
This is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void print_with_memo();
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char testText[15];
sprintf(testText,"Hello World" );
Memo1->Lines->Add(testText); // Works correct!
print_with_memo();
}
//---------------------------------------------------------------------------
void print_with_memo(textText)
{
char testText[15];
//TForm1::Memo1;
//TMemo *Memo1;
sprintf(testText,"Hi There" );
Memo1->Lines->Add(testText); // Error: Undefined symbol Memo1
}
//------------------------------------------------------------------------
Does someone know how to define/declare this Memo1 when it's used in a function???
Feb 17, 2009 at 9:30pm UTC
Button1Click is a TForm1 member function, print_with_memo isn't.
Is Memo1 a TForm1 member?
Feb 17, 2009 at 10:07pm UTC
yes, that's why it doesn't work in the function.
But maybe I can define/declare Memo1 as a TForm1 member in this function.
What do you think?
Feb 18, 2009 at 9:03am UTC
somebody an answer?
Feb 18, 2009 at 9:08am UTC
Make print_with_memo() a member of TForm1 .
Feb 18, 2009 at 9:37am UTC
Yes! thank you, it's working!
Topic archived. No new replies allowed.