How to close a file if successfully opened

Liste des GroupesRevenir à cl tcl 
Sujet : How to close a file if successfully opened
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 20. Jun 2024, 11:16:56
Autres entêtes
Message-ID : <bNicnXPg6cMFnOn7nZ2dnZfqnPadnZ2d@brightview.co.uk>
User-Agent : Pan/0.154 (Izium; 517acf4)
I have an app that reads config info from a .ini file.
But the first time the app is run there is no .ini file exits.

Below is the code I'm using to ensure that the .ini file is closed if
opened; but surely there's a better way?

I really want to get rid of the first if command

if {![file isfile $::config::filename]} {
    return
}
try {
    set fh [::ini::open $::config::filename -encoding utf-8 r]
    set ::config::geometry \
        [::ini::value $fh Window geometry [wm geometry .]]
    tk scaling [::ini::value $fh Window scale [tk scaling]]
    ttk::style theme use \
        [::ini::value $fh Window theme [ttk::style theme use]]
    set ::config::tab [::ini::value $fh Window tab]
} finally {
    if {[info exists fh] && $fh ne ""} {
        ::ini::close $fh
    }
}

Date Sujet#  Auteur
20 Jun 24 * How to close a file if successfully opened4Mark Summerfield
20 Jun 24 +- Re: How to close a file if successfully opened1Mark Summerfield
20 Jun 24 `* Re: How to close a file if successfully opened2greg
21 Jun 24  `- Re: How to close a file if successfully opened1Mark Summerfield

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal