SOS!!previous next button!!

Hello everyone!
Anyone can help me!?
i'm new in programming
i'm trying to make something like a slideshow in my form
i have a previous next button so each time i press the next button to go to a new image(something like a tutorial)
i could use all the help!!
thanks

Comments

  • Hello taouki,

    You can use a simple file to read and write for memorize the step you have done... *I have done the same as you do now*

    Why i use a file? not write down the code only in the app itself? because I want to make an app that can be renewable without change it source.

    For the app, i use .ini file and write some data there.
    There is a data name TIniFile on IniFiles.hpp header that you can use.

    -

    For example we have 4 images to be shown. So we need one variable to store the total image number. Next we need the file or image that want to be shown. Remember that the path must be clear or we must specify the full path of those images.

    So our .ini file will be like this

    [slideshow]
    total=4
    image[0]=d:my imagepicture1.jpg
    image[1]=d:my imagepicture2.jpg
    image[2]=d:my imagepicture3.jpg
    image[3]=d:my imagepicture4.jpg

    ----

    you can name the file anything you want, but for in this example i want to use that filename

    ----

    We have 2 button which is PrevButton and NextButton. A TImage which is SlideImg. Else we have a form *of course we we need it

    Declare this variable on your form by insert it inside the class (your Form class). You can put in either public or private section.

    [code]
    int TotSlide; // for your total slide number
    int CurSlide; // Current displayed slide
    [/code]

    Now write this on your OnLoad method of your form

    [code]
    //---------------------------------------------------------------------------
    void __fastcall TVirusForm::FormCreate(TObject *Sender)
    {
    TIniFile * ini = new TIniFile("D:\My File\setting.ini");
    // We specify the path of our ini file. For example it's name
    // is setting.ini

    TotSlide = ini->ReadInteger("slideshow","total",0);
    // the section is in [slideshow] section. the data is located
    // on total indent. If there is no the data, it will return 0

    CurSlide = 0; // I use a zero-based index so 0 means first
    }
    //---------------------------------------------------------------------------
    [/code]

    Now write this on your NextButton OnClick code

    [code]
    if(CurSlide < (TotSlide-1)) {
    // Remember zero-based index
    CurSlide += 1;
    // increasing the current preview slide
    SlideImg->Picture->LoadFromFile(
    ini->ReadString("SlideShow",
    "image["+CurSlide+"]",
    "d:my imageerror.jpg
    )
    // read the filename, if it's error it will
    // return an error image
    );
    }
    [/code]

    Now write to your PrevButton OnClick method

    [code]
    if(CurSlide > 0) {
    CurSlide -= 1;
    // decreasing the current preview slide
    SlideImg->Picture->LoadFromFile(
    ini->ReadString("SlideShow",
    "image["+CurSlide+"]",
    "d:my imageerror.jpg
    )
    // read the filename, if it's error it will
    // return an error image
    );
    }
    [/code]

    ----------------------------------------------------------------------

    We'are done...
  • thank you so much!!
    i had written something like this but the counter gave me a hard time!!
    really appreciate your help!:)
  • This post has been deleted.

  • a quick question
    why does it says invalid pointer addition for the HERE spot???
    Image3->Picture->LoadFromFile( ini->ReadString("SlideShow","image["+CurSlide+HERE"]",
    if i remove the + before and after the CurSlide it compiles fine but on click it show the error.bmp
    ???
  • My apology,

    Try this one:
    Image3->Picture->LoadFromFile(ini->ReadString("SlideShow","image["+IntToStr(CurSlide)+"]", ""));

    The error came because we use the '+' symbol which is actually the symbol for adding number.
    LoadFromFile() method use AnsiString parameter/argument. AnsiString type overload '+'. The overloaded '+' symbol means it can concat string to another string or numeric value. Like we can see in first case between "image[" and CurSlide
    The first operand which is "image[" is a string (we know from "" symbol) and next operand is a CurSlide which is integer. Compiler will use the overloaded '+' symbol which AnsiString defined and concat the string to integer.
    But in second case which is CurSlide and "]" string, we know that CurSlide is an integer value, so compiler will consider '+' symbol used as a numerical adding operation (like 1+2). But the second operand doesn't match the criteria (a numeric value must be added with numeric value too, again like 1+2) so it shows error "invalid pointer addition" <-- means compiler can't add two operands.

    So the solution is, we change the CurSlide variable from integer to be a string value. We do this by using IntToStr() function.

    The compiler will consider the '+' symbol is for string concat (like what i've told that it is overloaded symbol from AnsiString)

    Hope this can help,
  • This post has been deleted.
  • This post has been deleted.
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