Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should one class request info from another one?
    primarykey
    data
    text
    <p>I am working on a VB.NET batch PDF exporting program for CAD drawings. The programs runs fine, but the architecture is a mess. Basically, one big function takes the entire process from start to finish. I would like to make a separate class, or several, to do the exporting work. </p> <p><strong>Here's the problem:</strong><br /> Sometimes the pdf file which will be created by my program already exists. In this case, I would like to ask the user if he/she would like to overwrite existing PDFs. I only want to do this if there is actually something which will be overwritten and I only want to do this once. In other words, "yes" = "yes to all." It seems wrong to have the form (which will be calling this new PDF exporting class) figure out what the PDF files will be called and whether there will be any overwrites. In fact, it would be best to have the names for the PDF files determined as the individual CAD drawings are processed (because I might want to use information which will only become available after loading the files in the CAD program in the background). </p> <p><strong>Here's the question:</strong><br /> How should I handle the process of prompting the user? I would like to keep all GUI logic (even something as simple as a dialog box) out of my PDF exporting class. I need a way for the PDF exporting class to say, "Hey, I need to know if I should overwrite or skip this file," and the form class (or any other class) to say, "Um, ok, I'll ask the user and get back to you."</p> <p>It seems there ought to be some pattern to handle this situation. What is it? </p> <p><strong>Follow-ups:</strong></p> <p>Events: It seems like this is a good way to go. Is this about what the code should look like in the PDF exporting class?</p> <pre> Dim e As New FileExistsEventArgs(PDFFile) RaiseEvent FileExists(Me, e) If e.Overwrite Then 'Do stuff here End If </pre> <p>A crazy idea: What about passing delegate functions to the export method of the PDF exporting class to handle the overwrite case?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload